获取手机唯一标识符(UUID+KeyChain)

来源:互联网 发布:网易股票分时数据 编辑:程序博客网 时间:2024/05/01 14:09

使用UUID作为手机唯一标识符在app删除并重新安装后会重新生成。当我们把第一次生成的UUID保存到KeyChain中就能解决这个问题。
推荐大家使用SFHFKeychainUtils来操作keychain。
SFHFKeychainUtils的下载链接http://download.csdn.net/detail/u011173536/9452292

NSString *SERVICE_NAME = @"com.-----";//最好用程序的bundle idNSString * 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添加数据    }
0 0
原创粉丝点击