以编程方式获取iOS设备的IMEI或UDID [英] Programmatically obtaining the IMEI or UDID of an iOS Device

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

问题描述

1。)Apple是否允许开发人员检索用户设备的IMEI号和UDID?

1.) Does Apple permit developers to retrieve the IMEI number and UDID of user device?

2.如何以编程方式获取这些值?

2.) How can I obtain these values programmatically?

3。)如果Apple不允许开发人员收集IMEI号码,他们是否为设备提供任何其他唯一号码?

3.) If Apple doesn't allow developers to gather the IMEI number, do they provide any other unique number for the device?

推荐答案

Apple不再允许开发人员以编程方式获取UUID。但是,您可以使用解决方法来唯一标识应用中的设备。下面的代码允许您使用 CFUUIDCreate 创建唯一标识符。

Apple no longer allows developers to obtain the UUID programmatically anymore. There are, however, workarounds that you can use to uniquely identify devices in your app. The code below allows you to create a unique identifier using CFUUIDCreate.

Objective-C:

Objective-C:

- (NSString*)GUIDString {
    CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);
    CFStringRef newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
    NSString *guid = (__bridge NSString *)newUniqueIDString;
    CFRelease(newUniqueIDString);
    CFRelease(newUniqueID);
    return([guid lowercaseString]);
}

Swift:

func GUIDString() -> NSString {
    let newUniqueID = CFUUIDCreate(kCFAllocatorDefault)
    let newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
    let guid = newUniqueIDString as! NSString

    return guid.lowercaseString
}

一旦你有了这个唯一标识符,您可以将其存储在 NSUserDefaults ,核心数据,将其发送到Web服务等,以将此唯一ID与运行您的应用的设备相关联。您也可以在 NSString 上将其用作类方法,如图所示此处

Once you have this unique identifier, you can store it in NSUserDefaults, Core Data, send it up to a web service, etc, to associate this unique id with the device running your app. You can also use this as a class method on NSString as seen here.

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

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