ios IOS7 中的 UDID 替换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18868576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:18:57  来源:igfitidea点击:

UDID Replacement in IOS7

iosios7udid

提问by Avinash

Is there is a alternative for UDID. My app will not be going to App Store as i'm using enterprise distribution. So is there any replacement. I tied advertising identifier, open udid, UIID and secure UDID. But if the phone is reset then i will get a new UDID. Any help would be appreciated.

UDID 是否有替代方案。我的应用程序不会进入 App Store,因为我使用的是企业发行版。所以有没有替代品。我绑定了广告标识符,打开 udid,UIID 和安全 UDID。但是如果手机被重置,那么我会得到一个新的 UDID。任何帮助,将不胜感激。

采纳答案by Avinash

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.

在尝试了所有可能的替代品之后。广告标识符是最好的方法。即使在我测试时重置电话后,它仍然保持不变。如果用户在设置中关闭它,那么我们会得到一个空值。除了这个问题,这是迄今为止最好的替代品。如果我找到任何其他更好的替代品,将更新。

回答by Nitin Gohel

For above 6.0 iOS you can use identifierForVendorOr CFUUIDRef.

对于 6.0 以上的 iOS,您可以使用identifierForVendorOr 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

更新

As Leon Lucardiecomment he is right

作为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.

identifierForVendor 将在应用程序卸载/重新安装后更改。当应用程序(或来自同一供应商的另一个应用程序)安装在 iOS 设备上时,此属性中的值保持不变。当用户从设备中删除该供应商的所有应用程序并随后重新安装其中一个或多个应用程序时,该值会发生变化。

回答by Sandeep Khade

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

检查此链接UUID 和 UDID for iOS7

回答by Idan

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). With some answers here you would simply get rejected by Apple (my code has been approved in several apps of mine).

如您所知,如果您打算支持 iOS 5,那么您应该使用 OpenUDID(即使在 iOS 5 上,Apple 也限制读取 UDID)。有了这里的一些答案,您只会被 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 会发生变化。

回答by Haac74

I use the combination APNS token and vendorId. Both are checked to verify cellphone identity and I update them accordingly in cellphone and server when one of those change.

我使用组合 APNS 令牌和 vendorId。两者都经过检查以验证手机身份,当其中之一发生变化时,我会在手机和服务器中相应地更新它们。

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.

我只有一个应用程序,但是一旦我有了第二个应用程序,我可能会包含 adsId。

回答by sn86

You can use after ios 6+ with Swift 2.2 version.

您可以在 ios 6+ 之后使用 Swift 2.2 版本。

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

回答by Berk