如何在Swift中获取设备的唯一ID?
我需要一个ID在数据库中使用,并作为我的社交应用程序中的web服务的API-key。可以跟踪这些设备的日常使用情况,并将其查询限制在数据库中。
发布于 2020-02-05 01:01:42
if (UIDevice.current.identifierForVendor?.uuidString) != nil
{
self.lblDeviceIdValue.text = UIDevice.current.identifierForVendor?.uuidString
}
发布于 2019-03-08 06:27:56
class func uuid(completionHandler: @escaping (String) -> ()) {
if let uuid = UIDevice.current.identifierForVendor?.uuidString {
completionHandler(uuid)
}
else {
// If the value is nil, wait and get the value again later. This happens, for example, after the device has been restarted but before the user has unlocked the device.
// https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor?language=objc
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
uuid(completionHandler: completionHandler)
}
}
}
发布于 2016-06-01 18:39:14
我试过了
let UUID = UIDevice.currentDevice().identifierForVendor?.UUIDString
相反,
let UUID = NSUUID().UUIDString
而且它是有效的。
https://stackoverflow.com/questions/25925481
复制相似问题