iOS7应用程序向后兼容iOS5关于唯一标识符 [英] iOS7 app backward compatible with iOS5 regarding unique identifier
本文介绍了iOS7应用程序向后兼容iOS5关于唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用与iOS5和iOS6兼容。
到目前为止,我使用时没有问题:
My app is compatible with iOS5 and iOS6. Until now I had no problem using:
NSString DeviceID = [[UIDevice currentDevice] uniqueIdentifier];
现在iOS7和uniqueIdentifier不再工作我改为:
Now with iOS7 and with uniqueIdentifier not working anymore I changed to:
NSString DeviceID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
问题是,这对iOS5无效。
The problem is, this would not work for iOS5.
如何实现与iOS5的向后兼容?
How can I achieve backward compatibility with iOS5?
我试过这个,没有运气:
I tried this, with no luck:
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
// iOS 6.0 or later
NSString DeviceID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
#else
// iOS 5.X or earlier
NSString DeviceID = [[UIDevice currentDevice] uniqueIdentifier];
#endif
推荐答案
最佳推荐选项由Apple提供:
The best and recommend option by Apple is:
NSString *adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
将其用于5.0以上的每台设备。
Use it for every device above 5.0.
对于5.0,您必须使用uniqueIdentifier。最好检查它是否可用:
For 5.0 you have to use uniqueIdentifier. The best to check if it's available is:
if (!NSClassFromString(@"ASIdentifierManager"))
结合它会给你:
- (NSString *) advertisingIdentifier
{
if (!NSClassFromString(@"ASIdentifierManager")) {
SEL selector = NSSelectorFromString(@"uniqueIdentifier");
if ([[UIDevice currentDevice] respondsToSelector:selector]) {
return [[UIDevice currentDevice] performSelector:selector];
}
//or get macaddress here http://iosdevelopertips.com/device/determine-mac-address.html
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
这篇关于iOS7应用程序向后兼容iOS5关于唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文