简体   繁体   English

IOS7中的UDID替换

[英]UDID Replacement in IOS7

Is there is a alternative for UDID. 是否有UDID的替代方案。 My app will not be going to App Store as i'm using enterprise distribution. 我的应用程序不会进入App Store,因为我正在使用企业分发。 So is there any replacement. 那么有没有替代品。 I tied advertising identifier, open udid, UIID and secure UDID. 我绑定了广告标识符,打开udid,UIID和安全UDID。 But if the phone is reset then i will get a new UDID. 但如果手机重置,那么我将获得一个新的UDID。 Any help would be appreciated. 任何帮助,将不胜感激。

For above 6.0 iOS you can use identifierForVendor Or CFUUIDRef . 对于6.0以上的iOS,您可以使用identifierForVendorCFUUIDRef

-(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 UPDATE

As Leon Lucardie comment he is right 正如Leon Lucardie评论他是对的

identifierForVendor will change after app uninstall/reinstall. 在卸载/重新安装应用程序后,identifierForVendor将会更改。 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. 请参阅此处在iOS设备上安装app(或来自同一供应商的其他应用程序)时,此属性中的值保持不变。 The value changes when the user deletes all of that vendor's apps from the device and subsequently reinstalls one or more of them. 当用户从设备中删除所有该供应商的应用程序并随后重新安装其中一个或多个应用程序时,该值会更改。

You have to create vendor id then save it using keychain and get it back once you reset your phone using date time 您必须创建供应商ID,然后使用钥匙串保存它,并在使用日期时间重置手机后将其恢复

check this link UUID and UDID for iOS7 检查此链接iOS7的UUID和UDID

After trying all possible replacements. 在尝试所有可能的替换之后。 Advertising identifier is the best way to go. 广告标识符是最好的方式。 It remains same even after phone reset when i tested. 在我测试时,即使手机重置后它仍然保持不变。 If the user turn it off in the settings then we get a null value. 如果用户在设置中将其关闭,则我们获得空值。 Except for this hitch, this is the best replacement so far. 除了这个故障,这是目前为止最好的替代品。 Will update if i find any other better replacements. 如果我找到任何其他更好的替代品,将更新。

Easy, Just use this code: 简单,只需使用此代码:

-(NSString *)getUID{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
    // This is will run if it is iOS6 and above
        return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
    // This is will run before iOS6 and you can use openUDID or other
    // method to generate an identifier
        return [OpenUDID value];  
    }  
}

As you can understand, if you plan to support iOS 5 then you should use OpenUDID (Apple restrict reading the UDID even on iOS 5). 您可以理解,如果您计划支持iOS 5,那么您应该使用OpenUDID(Apple限制在iOS 5上读取UDID)。 With some answers here you would simply get rejected by Apple (my code has been approved in several apps of mine). 在这里有一些答案你只会被Apple拒绝(我的代码已经在我的几个应用程序中获得批准)。

Pay attention that identifierForVendor would change if your user would remove the app (or all vendor apps if there are several) and reinstall. 请注意,如果您的用户将删除应用程序(或所有供应商应用程序,如果有多个)并重新安装,则identifierForVendor会更改。

I use the combination APNS token and vendorId. 我使用组合APNS令牌和vendorId。 Both are checked to verify cellphone identity and I update them accordingly in cellphone and server when one of those change. 检查两者以验证手机身份,并在其中一个更改时在手机和服务器中相应地更新它们。

It´s still possible that both change, when the app is uninstalled and/or reset and stored for a few months, then both values would change. 当应用程序被卸载和/或重置并存储几个月时,两者都有可能发生变化,这两个值都会发生变化。

This will cause that next time the cellphone gets the app installed, it will be identified as a new one. 这将导致下次手机安装应用程序时,它将被识别为新的。

Additional to this I run a process in server that marks as deleted any device which hadn't connected to the server for two months. 除此之外,我在服务器中运行一个进程,将任何未连接到服务器的设备标记为已删除两个月。

In that case user authentication is required and cellphone is added again to the customer's pool of devices. 在这种情况下,需要用户身份验证,并再次将手机添加到客户的设备池中。

I have only one app yet, but once I have the second one I might include advertisingId. 我只有一个应用程序,但是一旦我有了第二个应用程序,我可能会包含advertisingId。

These blog posts by Ole should be helpful: Ole的这些博客文章应该会有所帮助:

iOS 5: http://oleb.net/blog/2011/09/how-to-replace-the-udid/ iOS 6+: http://oleb.net/blog/2012/09/udid-apis-in-ios-6/ iOS 5: http//oleb.net/blog/2011/09/how-to-replace-the-udid/ iOS 6+: http//oleb.net/blog/2012/09/udid-apis-in -ios-6 /

You can use after ios 6+ with Swift 2.2 version. 您可以在使用Swift 2.2版本的ios 6+之后使用。

var uniqueIdentifier: NSString!
uniqueIdentifier = UIDevice.currentDevice().identifierForVendor?.UUIDString

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM