使用UUID作为手机唯一标识符在app删除并重新安装后会重新生成。当我们把第一次生成的UUID保存到KeyChain中就能解决这个问题。
推荐大家使用SFHFKeychainUtils来操作keychain。
SFHFKeychainUtils的下载链接http://download.youkuaiyun.com/detail/u011173536/9452292
NSString *SERVICE_NAME = @"com.-----";//最好用程序的bundle id
NSString * str = [SFHFKeychainUtils getPasswordForUsername:@"UUID" andServiceName:SERVICE_NAME error:nil]; // 从keychain获取数据
if ([str length]<=0)
{
str = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // 保存UUID作为手机唯一标识符
[SFHFKeychainUtils storeUsername:@"UUID"
andPassword:str
forServiceName:SERVICE_NAME
updateExisting:1
error:nil]; // 往keychain添加数据
}