How to generate unique identifier which should work in all iOS versions?

前端 未结 3 674
南旧
南旧 2020-12-02 15:00

I want to get the unique identifier which should support all iOS versions..Can any one help me on this issue. As you know that apple is deprecated the UDID method, So there

3条回答
  •  天命终不由人
    2020-12-02 15:17

    Now Device Identifier change to UUID.You can get UUID With the help of following code:

    - (NSString *)getUUID
    {
        NSString *UUID = [[NSUserDefaults standardUserDefaults] objectForKey:@"uniqueID"];
        if (!UUID) {
            CFUUIDRef theUUID = CFUUIDCreate(NULL);
            CFStringRef string = CFUUIDCreateString(NULL, theUUID);
            CFRelease(theUUID);
            UUID = [(__bridge NSString*)string stringByReplacingOccurrencesOfString:@"-"withString:@""];
            [[NSUserDefaults standardUserDefaults] setValue:UUID forKey:@"uniqueID"];
        }
        return UUID;
    }
    

    It's Work in all iOS version.

提交回复
热议问题