質問

I have using the following code for get identifier

        deviceName = [[UIDevice currentDevice]uniqueIdentifier];

But i got the warning uniqueIdentifier is deprecated in ios5.

so how to get the identifier value in ios5?

役に立ちましたか?

解決

You can use the following code

if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
    // This will run if it is iOS6 or higher
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
   // This will run before iOS6 and you can use openUDID or other 
   // method to generate an identifier
}

And this way you can maintain the previous min requirement.

This identifier is unique for all the apps from one vendor. If you want unique identifier for device you need to use:

if (!NSClassFromString(@"ASIdentifierManager")) {
    // This will run before iOS6 and you can use openUDID, per example...
    return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

Warning: There is a bug on iOS6 that reports "null" identifier if the device was updated "by air" - More info

他のヒント

You can't get UUID anymore. It is forbidden to do so, your app will be rejected by Apple.

in ios 7 you better use [UIDevice identifierForVendor] or you run into trouble, because only a fake MAC gets returned.

The method demonstrated by J.Costa is the good one for iOS 6.

But if you want to keep the same identifier in your app when your user upgrade his phone, or within your several apps (Unless they share the same Bundle Seed ID), use this : https://github.com/blackpixel/BPXLUUIDHandler

Very useful!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top