What can be used with [UIDevice currentDevice]?

后端 未结 3 1417
终归单人心
终归单人心 2020-12-12 07:15

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

相关标签:
3条回答
  • 2020-12-12 07:27

    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];
    
    0 讨论(0)
  • 2020-12-12 07:46

    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.

    0 讨论(0)
  • 2020-12-12 07:50

    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

    0 讨论(0)
提交回复
热议问题