Programmatically obtaining the IMEI or UDID of an iOS Device

前端 未结 1 1548
北恋
北恋 2021-01-28 18:40

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

2.) How can I obtain these values programmatically?

3.) If Apple doesn\'t a

相关标签:
1条回答
  • 2021-01-28 18:46

    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:

    - (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
    }
    

    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.

    0 讨论(0)
提交回复
热议问题