如何在Swift中获取唯一的设备ID?(How to get a unique device ID in Swift?)

编程入门 行业动态 更新时间:2024-10-28 14:22:53
如何在Swift中获取唯一的设备ID?(How to get a unique device ID in Swift?)

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

我需要一个ID在数据库中使用,并作为我的社交应用程序中的Web服务的API密钥。 某些东西要跟踪这个设备的日常使用,并将其查询限制到数据库。

谢谢!

How can I get a devices unique ID in Swift?

I need an ID to use in the database and as the API-key for my web service in my social app. Something to keep track of this devices daily use and limit its queries to the database.

Thanks!

最满意答案

你可以使用(Swift 3):

UIDevice.current.identifierForVendor!.uuidString

对于旧版本:

UIDevice.currentDevice().identifierForVendor

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

UIDevice.currentDevice().identifierForVendor!.UUIDString

在用户卸载该应用程序之后,不再有唯一标识设备的方法。 文件说:

在iOS设备上安装应用程序(或同一供应商的其他应用程序)时,该属性的值保持不变。 当用户从设备中删除所有供应商的应用程序并随后重新安装一个或多个应用程序时,该值会发生变化。

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

You can use this (Swift 3):

UIDevice.current.identifierForVendor!.uuidString

For older versions:

UIDevice.currentDevice().identifierForVendor

or if you want a string:

UIDevice.currentDevice().identifierForVendor!.UUIDString

There is no longer a way to uniquely identify a device after the user uninstalled the app(s). The documentation says:

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.

You may also want to read this article by Mattt Thompson for more details: http://nshipster.com/uuid-udid-unique-identifier/

Update for Swift 4.1, you will need to use:

UIDevice.current.identifierForVendor?.uuidString

更多推荐

本文发布于:2023-07-04 17:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设备   如何在   Swift   device   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!