xcode 方法 [[UIDevice currentDevice] uniqueIdentifier] 不再允许,我需要一个替代方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9396187/
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-09-14 23:24:15  来源:igfitidea点击:

Method [[UIDevice currentDevice] uniqueIdentifier] is not allowed any more, I need an alternative

objective-ciosxcode

提问by user784625

I'm using [[UIDevice currentDevice] uniqueIdentifier]in all of my apps, Apple is not allowing the use of uniqueIdentifieranymore. I need something to use that replaces the uniqueIdentifierwhich I can use to recognize a user even when the user deletes the app and installs it again, (and also get my app approved by apple).

我在我[[UIDevice currentDevice] uniqueIdentifier]所有的应用程序中都在使用,Apple 不允许再使用uniqueIdentifier了。我需要一些东西来代替uniqueIdentifier我可以用来识别用户的东西,即使用户删除了应用程序并再次安装它,(也让我的应用程序得到苹果的批准)。

Thanks

谢谢

回答by Joe

The documentationrecommends what to do in this section.

文档建议了在本节中执行的操作。

Special Considerations
Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

特殊注意事项
不要使用 uniqueIdentifier 属性。要创建特定于您的应用程序的唯一标识符,您可以调用 CFUUIDCreate 函数来创建 UUID,并使用 NSUserDefaults 类将其写入默认数据库。

To make sure that the unique identifier remains after you delete the app you should store it in the keychainrather than NSUserDefaults. Using the keychain you will also be able to share the same unique ID across all of your apps on the same device using keychain access groups. This approach will prevent you from incorrectly tracking users after the device is no longer theirs, and it will be available on any new iDevice they restore from backup.

为了确保在删除应用程序后唯一标识符仍然存在,您应该将其存储在钥匙串中而不是 NSUserDefaults 中。使用钥匙串,您还可以使用钥匙串访问组在同一设备上的所有应用程序之间共享相同的唯一 ID 。这种方法将防止您在设备不再属于他们后错误地跟踪用户,并且可以在他们从备份中恢复的任何新 iDevice 上使用。

回答by digipeople

Update for iOS 7 and prior:

iOS 7 及更早版本的更新:

+ (NSString *)uniqueDeviceIdentifier
{
    NSString *device_id = nil;

    if ([[self deviceModel] isEqualToString:@"Simulator iOS"]) {
        // static id for simulator
        device_id = @"== your random id ==";
    }
    else if (CurrentIOSVersion >= 6.f) {
        // iOS 6 and later
        device_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    }
    else {
        // iOS 5 and prior
        SEL udidSelector = NSSelectorFromString(@"uniqueIdentifier");
        if ([[UIDevice currentDevice] respondsToSelector:udidSelector]) {
            device_id = [[UIDevice currentDevice] performSelector:udidSelector];
        }
    }
    NSLog(@">>>>>> device_id: %@", device_id);
    return device_id;
}

Device model you can receive through:

您可以通过以下方式接收的设备型号:

+ (NSString*)deviceModel
{
    static NSString *device_model = nil;

    if (device_model != nil)
        return device_model;

    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *str = @(systemInfo.machine);

    return device_model;
}

回答by ???