简体   繁体   中英

What can be used with [UIDevice currentDevice]?

What can be with [UIDevice currentDevice] , such as uniqueIdentifier? Thanks!

Because this is slightly out of date now I am just giving an up to date answer.

Because Apple has seen fit to stop developers using the [[UIDevice currentDevice] uniqueIdentifier]; from iOS 6 onwards which Suhail Patels answer advices to use. They have now started telling developers to use [[UIDevice currentDevice] identifierForVendor]; , but some developers are confused on whether they are still allowed to use uniqueIdentifier even if they are still developing for iOS 5 and below or not. Apple have been a bit fussy about this just saying :

"Apps that use the `UDID` will be rejected in the App Store review process.." 

Come on Apple give us a bit more detail.

Anyway because of the confusion behind this some developers have started using OpenUDID to get a unique identifier. Here is some code on how it can be used:

    if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
        // Use: [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
        // Use: [OpenUDID value];
    }

EDIT

Some developers have also now seen fit to start using the MAC Address since UDID has been deprecated. This is because the MAC addresses are hardware based and therefore can't be changed. For those of you that which to go for the MAC Address way apple have provided some sample code on Getting MAC Address .

For iOS 5, you can create a new, but not unique identifier with this:

CFUUIDRef UIID = CFUUIDCreate(NULL);
CFStringRef UIIDString = (CFUUIDCreateString(NULL, UIID));
NSString *string = [NSString stringWithFormat:@"%@",UIIDString];     

Save it in a file and use it like unique identifier

All the properties and methods associated with a UIDevice Object are described in the UIDevice Class Reference

To access the Unique Identifer, you can do something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM