最近项目中需要用到设备的编号,取值idfa,idfv等值,都有存在变化的可能,现在用这种方式可以实现设备唯一编号,就算删除app从新安装也不变,亲测了一下,第一次取值为
f972224649a94e6f9eb105e897284561,
后面删除了APP,又重新安装后,打印设备的ID信息,还是
f972224649a94e6f9eb105e897284561,
亲测有效。
第三方开源代码
https://github.com/soffes/SAMKeychain
使用方法
//获取设备信息32 位字符串
-(NSString *)getDeviceString{
NSString * deviceUUIDStr = [SAMKeychain passwordForService:@"你的app bundle identifier" account:@"uuid"];
if (deviceUUIDStr == nil || [deviceUUIDStr isEqualToString:@""])
{
deviceUUIDStr = [[[UIDevice currentDevice].identifierForVendor.UUIDString stringByReplacingOccurrencesOfString:@"-" withString:@""] lowercaseString];
[SAMKeychain setPassword: deviceUUIDStr forService:@"你的app bundle identifier"account:@"uuid"];
}
return deviceUUIDStr;
}