IOS7中的UDID替换

前端之家收集整理的这篇文章主要介绍了IOS7中的UDID替换前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
UDID是否有替代方案我的应用程序在我正在使用企业分发时不会去App Store.那有什么替换我绑定广告标识符,打开udid,UIID和安全的UDID.但如果手机被重置,那么我将得到一个新的UDID.任何帮助将不胜感激.

解决方法

对于6.0以上的iOS,您可以使用identifierForVendor或CFUUIDRef.
-(NSString*)uniqID
{
    NSString* uniqueIdentifier = nil;
    if( [UIDevice instancesRespondToSelector:@selector(identifierForVendor)] ) {
        // iOS 6+
        uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
        // before iOS 6,so just generate an identifier and store it
        uniqueIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"identifierForVendor"];
        if( !uniqueIdentifier ) {
            CFUUIDRef uuid = CFUUIDCreate(NULL);
            uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL,uuid);
            CFRelease(uuid);
            [[NSUserDefaults standardUserDefaults] setObject:uniqueIdentifier forKey:@"identifierForVendor"];
        }
    }
return uniqueIdentifier;
}//

UPDATE

正如Leon Lucardie所言,他是对的

identifierForVendor will change after app uninstall/reinstall. See here The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.

猜你在找的iOS相关文章