简体   繁体   English

[UIDevice currentDevice]可以使用什么?

[英]What can be used with [UIDevice currentDevice]?

What can be with [UIDevice currentDevice] , such as uniqueIdentifier? [UIDevice currentDevice]可以是什么,例如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]; 因为Apple认为适合阻止开发人员使用[[UIDevice currentDevice] uniqueIdentifier]; from iOS 6 onwards which Suhail Patels answer advices to use. iOS 6开始, Suhail Patels回答要使用的建议。 They have now started telling developers to use [[UIDevice currentDevice] identifierForVendor]; 他们现在已经开始告诉开发人员使用[[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. ,但是即使他们仍在为iOS 5和更低iOS 5开发,一些开发人员对于是否仍然允许使用uniqueIdentifier感到困惑。 Apple have been a bit fussy about this just saying : Apple对此一直有点挑剔:

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

Come on Apple give us a bit more detail. 来吧Apple给我们更多的细节。

Anyway because of the confusion behind this some developers have started using OpenUDID to get a unique identifier. 无论如何,由于其背后的困惑,一些开发人员已开始使用OpenUDID来获取唯一标识符。 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. 由于不推荐使用UDID因此一些开发人员现在也适合开始使用MAC地址。 This is because the MAC addresses are hardware based and therefore can't be changed. 这是因为MAC地址基于硬件,因此无法更改。 For those of you that which to go for the MAC Address way apple have provided some sample code on Getting MAC Address . 对于那些想要使用MAC地址方式的人,苹果在“ 获取MAC地址”中提供了一些示例代码。

For iOS 5, you can create a new, but not unique identifier with this: 对于iOS 5,您可以使用以下命令创建一个新的但不是唯一的标识符:

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 与UIDevice对象关联的所有属性和方法在《 UIDevice类参考》中进行了描述。

To access the Unique Identifer, you can do something like: 要访问唯一标识符,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 替代[UIDevice currentDevice] .identifierForVendor - Alternative to [UIDevice currentDevice].identifierForVendor UIDevice.currentDevice()。orientation.isLandscape的目标c等效项是什么? - What is the objective c equivalent of UIDevice.currentDevice().orientation.isLandscape? UIDevice.currentDevice()。beginGeneratingDeviceOrientationNotifications()无法正常工作 - UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications() not working Swift UIDevice.currentDevice()无法编译 - Swift UIDevice.currentDevice() not compiling UIDevice currentDevice模型可能的值 - UIDevice currentDevice model possible values [[UIDevice currentDevice] systemName] 的可能值; - Possible values for [[UIDevice currentDevice] systemName]; 如何设置通知对象的“ UIDevice.currentDevice()”? - How to set the 'UIDevice.currentDevice()' for object of notification? 使用OCMock模拟[[UIDevice currentDevice] userInterfaceIdiom] - Using OCMock to mock [[UIDevice currentDevice] userInterfaceIdiom] iOS9:替代UIDevice.currentDevice()。setValue(...)强制定位 - iOS9: Alternative to UIDevice.currentDevice().setValue(…) to force orientation 不使用[[UIDevice currentDevice] setOrientation强制LandScape方向:UIInterfaceOrientationAnyOrientation] - Forcing LandScape orientation without using [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationAnyOrientation]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM