获取设备唯一标识 uuid(采用第三方库SSKeychain)

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;

}

上一篇:iOS获取设备唯一标识的各种方法?IDFA、IDFV、UDID分别是什么含义?


下一篇:在SQL Server中使用CLR调用.NET方法