gpt4 book ai didi

php - 将变量从 php 发送到 iOS

转载 作者:行者123 更新时间:2023-11-29 10:33:54 24 4
gpt4 key购买 nike

我正在尝试让我的 iOS 应用程序从 php 文件接收变量。
假设我的 php 网站包含变量 $number=5。将该变量发送到我的应用程序的最简单方法是什么?也许是在应用程序中按下一个按钮,从网站获取变量并将其显示在文本字段中?

如果有人能给我一些建议,我将不胜感激。请记住,我是菜鸟。谢谢!

最佳答案

您描述问题的方式永远行不通,因为这是两个完全不同的设备,没有共享内存。

我向您推荐的是给您一些教程,以正确的方式指导您。我认为您应该为您的网站和需要数据的设备之间的通信创建一个 API。

第一个是在 PHP 中创建您自己的 API: http://css.dzone.com/articles/create-your-own-xmljsonhtml

第二个用于联系 objective-c 中的 API: http://www.raywenderlich.com/58682/introduction-restkit-tutorial

如果你也想要,这里有一些我制作的快速代码

let listData = NSData(contentsOfURL: NSURL(string: "http://yourhost.com/api/categories")!)
let prop = NSPropertyListSerialization.propertyListFromData(listData, mutabilityOption: NSPropertyListMutabilityOptions.allZeros, format: nil, errorDescription: nil) as NSArray // or NSDictionary. NSDictionary are for key value, NSArray are for an Array

希望对您有所帮助。

更新

如果您有 en webView,我只是快速搜索了“ios webview pass data”,并找到了这个 stackoverflow 链接: Passing Data To and From an Embedded UIWebView

关于php - 将变量从 php 发送到 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28073516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com