//先从钥匙串中获取
NSString*uuid = [SFHFKeychainUtils getPasswordForUsername:@"app.UUID"andServiceName:@"app.service"error:nil];
//如果钥匙串中没有uuid
if(!uuid){
//则创建
CFUUIDRefpuuid =CFUUIDCreate(nil);
CFStringRefuuidString =CFUUIDCreateString(nil, puuid );
NSString*result = (__bridgeNSString*)uuidString;
CFRelease(puuid);
CFRelease(uuidString);
//去掉uuid中的间隔符'-'
NSString*newString = [resultstring ByReplacingOccurrencesOfString:@"-"withString:@""];
//并且存储到钥匙串中以防用户卸载程序后 下次获取到的UUId 不同。
[SFHFKeychainUtilsstoreUsername:@"app.UUID"andPassword:newStringforServiceName:@"app.service"updateExisting:YES error:nil];
returnnewString;
}
else
return uuid;