SSKeyChain 下载链接: http://pan.baidu.com/s/1booV3VD 密码: ivdi
/**
* 获取设备唯一标识 uuid
*/
+(NSString*) uuid {
//保存一个UUID字符串到钥匙串:
CFUUIDRef uuid = CFUUIDCreate(NULL);
assert(uuid != NULL);
CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
[SSKeychain setPassword: [NSString stringWithFormat:@"%@", uuidStr]
forService:@"com.liukena.ios.JiuyierNutrition"account:@"user"];
//从钥匙串读取UUID:
NSString *uuidString = [JYEDeviceInfo getDeviceId];
//注意“JYEDeviceInfo”是类名,替换成相应的类名即可。。(+ (NSString *)getDeviceId,本身是类方法,需要类名调用)
// NSLog(@"[NSString getDeviceId] = %@",uuidString);
return uuidString;
}
+ (NSString *)getDeviceId
{
NSString * currentDeviceUUIDStr = [SSKeychain passwordForService:@" "account:@"uuid"];
if (currentDeviceUUIDStr == nil || [currentDeviceUUIDStr isEqualToString:@""])
{
NSUUID * currentDeviceUUID = [UIDevice currentDevice].identifierForVendor;
currentDeviceUUIDStr = currentDeviceUUID.UUIDString;
currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];
[SSKeychain setPassword: currentDeviceUUIDStr forService:@" "account:@"uuid"];
}
return currentDeviceUUIDStr;
}