Deprecated in iOS 5.0
来源:互联网 发布:拦截软件广告的软件 编辑:程序博客网 时间:2024/05/19 05:34
见苹果文档,从iOS 5.0开始,UIDevice中uniqueIdentifier属性不再有效:
Deprecated in iOS 5.0
uniqueIdentifier
Do not use the uniqueIdentifier property. To create a unique identifierspecific to your app, you
can call the CFUUIDCreate function to create a UUID,and write it to the defaults database using
the NSUserDefaults class.
对于许多和设备UDID有关联的应用(尤其是企业应用),这真是一场灾难。然而面对苹果
如此强势的做法,我们别无选择。只能如苹果所说的,用CFUUIDCreate函数替代
uniqueIdentifier,然后把它保存到程序的defaults数据库中。
我不知道有多少人开始着手更新老的uniqueIdentifier代码,但我在github发现了一个第
3方开源库:UIDevice-with-UniqueIdentifier-for-iOS-5,它为我们解决了许多麻烦:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
它实际上包括了2个Category:
NSString+MD5Addition 和 UIDevice+IdentifierAddition
直接将4个.m文件和.h文件拷贝到项目中,然后直接import即可。
根据readme文件所述,有两种Identifier,分别用[[UIDevice
currentDevice]uniqueDeviceIdentifier] 和 [[UIDevice
currentDevice]uniqueGlobalDeviceIdentifier]来生成。
前者在同一app中唯一,后者在不同的app中仍然唯一。
对于前者,它使用“mac地址+bundleIdentifier”方案生成MD5值作为Identifier:
- (NSString *) uniqueDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *bundleIdentifier = [[NSBundle mainBundle]bundleIdentifier];
NSString *stringToHash = [NSStringstringWithFormat:@"%@%@",macaddress,
bundleIdentifier];
NSString *uniqueIdentifier = [stringToHash stringFromMD5];
return uniqueIdentifier;
}
后者则使用“mac地址”生成的MD5值作为Identifier(因为Mac地址本身就是一个
GUID):
武汉大学pd4ml evaluation copy. visit http://pd4ml.com
- (NSString *) uniqueGlobalDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *uniqueIdentifier = [macaddress stringFromMD5];
return uniqueIdentifier;
}
如果你想和iOS 4.0保持兼容,那么可以这样写:
// IOS 5.0:uniqueIdentifier is deprecated
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
return [[UIDevicecurrentDevice]uniqueDeviceIdentifier];
#endif
return [[UIDevicecurrentDevice] uniqueIdentifier];
- Deprecated in iOS 5.0
- addTimeInterval Deprecated in iOS 4.0
- IOS 5.0:uniqueIdentifieris deprecated
- IOS 5.0:uniqueIdentifieris deprecated
- 'dispath_get_current_queue'is deprecated:fist deprecated in iOS 6.0的解决办法
- cString is deprecated :first deprecated in iOS 2.0
- 'sizeWithFont:' is deprecated: first deprecated in iOS 7.0 - Use -sizeWithAttributes:
- "dismissModalViewControllerAnimated" is deprecated : first deprecated in iOS 6.0
- [问题记录]cString is deprecated :first deprecated in iOS 2.0
- [问题记录]'dismissModalViewControllerAnimated:' is deprecated: first deprecated in iOS 6.0
- UITextAlignmentCenter' is deprecated: first deprecated in iOS 6.0 UITextAlignmentCenter
- 'minimumFontSize' is deprecated: first deprecated in iOS 6.0
- NSDate addTimeInterval Deprecated in iOS 4.0
- UIAlertView is deprecated in iOS 8.
- Replacement for deprecated sizeWithFont: in iOS 7?
- sizeWithFont:constrainedToSize:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithS
- presentModalViewController deprecated in ios6
- presentModalViewController deprecated in ios6
- linux 环境下Tomcat中查看logs日志
- 如何实现Video Record的时候来新的MMS 仍然可以有提示
- web.xml中配置servlet
- file_get_contents和curl函数
- ATV漏电
- Deprecated in iOS 5.0
- 多行文本编辑时,不显示不能完整显示的行
- 多行文本编辑时,同一行编辑不同类型的字符时自动换行的问题
- 如何使开机动画只播一次
- 算法复杂度
- php中获取url与物理路径的总结
- GPU Accelerated Compositing in Chrome
- Debugging with the Maven Jetty Plugin in Eclipse
- 小伟2011提供伤感QQ日志_爱不是能转角,爱情已告别了