我使用下面的代码来获取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。我认为每次重新安装相同的应用程序时都应该是相同的。请帮帮我。
发布于 2017-01-30 21:27:35
我觉得你应该试试这个,
NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];发布于 2017-01-30 23:44:22
您需要深入研究为什么对passwordForService:的调用返回nil (这显然是您的症状)。如果SSKeychain没有提供错误,您将需要在代码中放置日志记录或断点,以查看实际的错误代码。
如果找不到它,那么您需要确保您正在成功编写(您没有检查setPassword:...中的错误)。如果它可以成功写入,但下次安装时无法读取,则需要检查是否没有更改访问组或签名密钥。如果因为权限而不是读(或写),你需要确保你没有在设备被锁定时尝试读/写(除非你已经为此正确地设置了权限)。
基本上,检查您的错误,并从那里开始。
https://stackoverflow.com/questions/41937006
复制相似问题