What can be used with [UIDevice currentDevice]?

笑着哭i 提交于 2019-12-17 21:22:26

问题


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


回答1:


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];



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/7128828/what-can-be-used-with-uidevice-currentdevice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!