iOS7 app backward compatible with iOS5 regarding unique identifier

后端 未结 3 760
天命终不由人
天命终不由人 2020-12-06 02:35

My app is compatible with iOS5 and iOS6. Until now I had no problem using:

NSString DeviceID = [[UIDevice currentDevice] uniqueIdentifier];

相关标签:
3条回答
  • 2020-12-06 02:42

    Why just not to use CFUUIDRef and be independent with iOS verion?

    CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
    
    self.uuidString = (NSString *)CFUUIDCreateString(NULL,uuidRef);
    
    CFRelease(uuidRef);
    

    And of course remember calculated uuidString in the Keychain(in case of application removal)?

    Here is written how to use keychain

    0 讨论(0)
  • 2020-12-06 02:45

    As hard replacement of static macro, you can try dynamic if statement to check it.

    UIDevice has property named 'systemVersion' and you can check this.

    0 讨论(0)
  • 2020-12-06 02:59

    The best and recommend option by Apple is:

     NSString *adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    

    Use it for every device above 5.0.

    For 5.0 you have to use uniqueIdentifier. The best to check if it's available is:

    if (!NSClassFromString(@"ASIdentifierManager"))
    

    Combining that will give you:

    - (NSString *) advertisingIdentifier
    {
        if (!NSClassFromString(@"ASIdentifierManager")) {
            SEL selector = NSSelectorFromString(@"uniqueIdentifier");
            if ([[UIDevice currentDevice] respondsToSelector:selector]) {
                return [[UIDevice currentDevice] performSelector:selector];
            }
            //or get macaddress here http://iosdevelopertips.com/device/determine-mac-address.html
        }
        return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    }
    
    0 讨论(0)
提交回复
热议问题