别着急,我是 I OS 和 Swift 的新手 :)。我正在尝试使用 swift 创建一个 IOS 应用程序。我有一个正常工作的 Web View 显示,显示网站。耶!! 我现在需要做的是创建一个唯一标识符,该标识符存储在本地,并在应用程序打开时发送到远程服务器。我知道我可以使用这个...
UIDevice.currentDevice().identifierForVendor!.UUIDString
但是我想将它存储在本地以供将来使用,并在每次打开应用程序时将其发送到远程服务器。我已经对此进行了研究,并找到了其他对象的答案,而不是 WebView 。
如果有人知道此解决方案的教程或示例代码,我将不胜感激。
更新
let uuid = UIDevice.currentDevice().identifierForVendor!.UUIDString
对于我使用的 url
let url= NSURL (string:"https://example.com");
我可以做这样的事情吗?还是喜欢?
let url= NSURL (string:"https://example.com");
let requestobj= NSURLRequest(URL:url! ADD VAR HERE? );
ADD VAR HERE 是要传递到服务器的 uuid,我可以用 php 脚本捕获它?
最新更新..
我很难将它集成到我现有的代码中。放在哪里最好?
import UIKit
class ViewController: UIViewController {
let uuid = UIDevice.currentDevice().identifierForVendor!.UUIDString
@IBOutlet weak var WebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL (string: "https://example.com");
let requestObj = NSURLRequest(URL: url?)
WebView.loadRequest(requestObj);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
最佳答案
这是我一直在寻找的答案。感谢大家的帮助!
let device_uuid = UIDevice.currentDevice().identifierForVendor!.UUIDString
let api_host = "https://example.com?uuid=" + device_uuid
let url = NSURL(string: api_host)
let req = NSURLRequest(URL: url!)
WebView.loadRequest(req);
显然我需要做的是将我的 URL 构建到一个变量中。然后我可以使用 NSURL 构造它并从那里使用它。本指南帮助了我。如果这不是您正在做的,请忽略 ruby on rails 部分。
关于ios - 在 webview 中创建唯一标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35706975/