OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 iOS 10.2 在同一设备上获取不同的 UUID [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:45
标题: ios - 使用 iOS 10.2 在同一设备上获取不同的 UUID

我正在使用下面的代码来获取 UUID。

 -(NSString *)updateUserPhoneDetails{

    NSString *retrieveuuid = [SSKeychain passwordForService"com.testUser" account"testUser"];    
    NSString *uniqueID;
    if (retrieveuuid == nil) {
        NSString *uuid = [[NSUUID UUID] UUIDString];
        uniqueID=[uuid stringByReplacingOccurrencesOfString"-" withString""];
        NSLog(@"Create new uuid : %@",uniqueID);
        //Store the password in Keychain
        NSError *error = nil;
        [SSKeychain setPassword:uuid forService"com.testUser" account"testUser" error:&error];
    }else{
        uniqueID=[retrieveuuid stringByReplacingOccurrencesOfString"-" withString""];
        NSLog(@"uniqueID  : %@",uniqueID);
    }
    return uniqueID;
}

以上代码在 iOS 10.0 之前运行良好。 我已经在 iPhone 7、iPhone 5s 上进行了测试,但得到了一些不同的 UUID。 我认为每次重新安装相同的应用程序时它都应该相同。 请帮帮我。



Best Answer-推荐答案


我觉得你应该试试这个,

 NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

关于ios - 使用 iOS 10.2 在同一设备上获取不同的 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41937006/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4