How can I retrieve the UDID on iOS?

前端 未结 10 1314
礼貌的吻别
礼貌的吻别 2020-12-14 06:05

I was wondering if it was possible to find out the UDID of the user\'s iPhone. Can someone shed some light?

10条回答
  •  执念已碎
    2020-12-14 06:47

    Like some said, in iOS5 this has been deprecated:

    NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];
    

    Apple now has 3 APIs to get a UUID(Universally Unique Identifier) of the device:

    Alternative 1 (NSUUID class):

    NSString *udid = [[NSUUID UUID] UUIDString];
    

    Alternative 2 (UIDevice class):

    NSString *udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    

    Alternative 3 (ASIdentifierManager class, requieres AdSupport framework):

    NSUUID *UUID = [[ASIdentifierManager sharedManager] advertisingIdentifier];
    NSString *udid = [UUID UUIDString];
    

    But they are all alphanumeric, and a tipical device unique identifier is only digits. So thos 3 APIs are useless, and the old [[UIDevice currentDevice] uniqueIdentifier] still works in iOS6, but for how long?

    If the "deprecated" warning bugs you, just add:

    #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    

    Hope it helps!

提交回复
热议问题