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

查看:1432
本文介绍了如何在Swift中获取唯一的设备ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I get a devices unique ID in Swift?

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

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.

谢谢!

推荐答案

你可以使用它(Swift 3):

You can use this (Swift 3):

UIDevice.current.identifierForVendor!.uuidString

旧版本:

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:


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

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,您需要使用:

Update for Swift 4.1, you will need to use:

UIDevice.current.identifierForVendor?.uuidString

这篇关于如何在Swift中获取唯一的设备ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆