ios - 如何在 Swift 中获取唯一的设备 ID?

标签 ios swift uuid uniqueidentifier

如何在 Swift 中获取设备的唯一 ID?

我需要一个 ID 在数据库中使用,并作为我的社交应用中的 Web 服务的 API key 。用于跟踪该设备日常使用情况并限制其对数据库的查询的东西。

最佳答案

您可以使用这个(Swift 3):

UIDevice.current.identifierForVendor!.uuidString

对于旧版本:

UIDevice.currentDevice().identifierForVendor

或者如果你想要一个字符串:

UIDevice.currentDevice().identifierForVendor!.UUIDString


用户卸载应用程序后,不再有办法唯一地标识设备。文档说:

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.


您可能还想阅读 Mattt Thompson 的这篇文章以了解更多详细信息:
http://nshipster.com/uuid-udid-unique-identifier/

更新 Swift 4.1,您将需要使用:

UIDevice.current.identifierForVendor?.uuidString

关于ios - 如何在 Swift 中获取唯一的设备 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52310419/

相关文章:

java - 通过 UUID 生成密码重置 token

swift - 将 Sprite Kit View 添加到 UIView Xcode 8.2.1

ios - 将 UITextField 委托(delegate)连接到自定义 TableView 单元格的文件所有者不起作用 Swift 3

swift - 如何访问嵌套在结构中的结构

php - 加密安全的唯一 ID

javascript - 将漫画变成 iPhone 网络应用程序

iOS SDK 录制视频而不保存到相册

ios - 具有大量数据 Swift 的 CollectionView

ios - 不会为每个推送通知调用 didReceiveRemoteNotification

php - 替代 MySQL 的 UUID Version 1 函数?