以编程方式获取IOS设备的UDID? [英] get UDID of IOS device programmatically?

查看:381
本文介绍了以编程方式获取IOS设备的UDID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式获取iOS设备的UDID。我使用以下代码获取iOS设备的UDID。

I want to get UDID of iOS device programmatically. I am using the following code to get UDID of iOS device.

NSUUID *uuid = [NSUUID UUID];
NSString *uuidString = uuid.UUIDString;

但我得到的输出与我设备的实际UDID不同。

But output I get is different from actual UDID of my device.

推荐答案

NSString* Identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+
  NSLog(@"output is : %@", Identifier);

Swift 2.X(此处X以上版本均为2.0以上版本)

let Identifier: String = UIDevice.currentDevice().identifierForVendor().UUIDString()
NSLog("output is : %@", Identifier)

Swift3

let Identifier = UIDevice.current.identifierForVendor?.uuidString

    NSLog("output is : %@", Identifier! as String)

其他参考


Apple显然已开始删除对UDID的访问权限iOS5中的(唯一设备标识符)。无论如何,您现在可以用于识别目的的最好方法是使用UUID(通用唯一标识符)。这必须基于每个应用程序。也就是说,无法再识别设备,但您可以在设备上识别应用程序。只要用户没有完全删除应用程序,那么此标识符将在应用程序启动之间保持不变,至少让您使用设备上的特定应用识别同一用户。不幸的是,如果用户完全删除然后重新安装应用程序,那么ID将会改变,但这是任何人都可以做的最好的。

Apple is apparently starting to remove access to the UDID (Unique Device IDentifier) in iOS5. In any event, the best you can now do for identification purposes is to use a UUID (Universally Unique IDentifier). This has to be on a per-app basis. That is, there is no way to identify the device any longer, but you can identify an app on a device.As long as the user doesn’t completely delete the app, then this identifier will persist between app launches, and at least let you identify the same user using a particular app on a device. Unfortunately, if the user completely deletes and then reinstalls the app then the ID will change, but this is the best anyone can do going forward.

这篇关于以编程方式获取IOS设备的UDID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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