ios - 以编程方式获取 iOS 设备的 IMEI 或 UDID

标签 ios iphone swift

1.) Apple 是否允许开发者检索用户设备的 IMEI 号码和 UDID?

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

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

最佳答案

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

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 上的类方法,如 here 所示。 .

关于ios - 以编程方式获取 iOS 设备的 IMEI 或 UDID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31075049/

相关文章:

ios - 在 iphone 应用程序中调用 exit(0)

objective-c - Objc-C 到 Swift : How to create a property in Swift that guarantees it's of a certain type when callers use it?

swift - 如何制作可重置的 RxSwift 计时器?

ios - 通过 Swift 3 和 Alamofire 4 使用 JSON 和自定义 header 上传照片/文件 | iOS | swift

ios - CoreData加密提交到应用商店时是否需要任何类型的额外文件

ios - 由于此错误 "Receiver (<ViewController: ) has no segue with identifier",Segue 将无法执行,但已识别出 segue

ios - Objective C setFrame 不适用于 UIView

ios - Xcode 上的 Swift._ArrayBuffer._copyContents

iphone - iphone sdk 4.0 中按钮尺寸变小

iphone - 在 iPhone 模拟器中禁用位置服务?