获取iOS设备唯一标识 uuid

获取uuid


介绍一个轻量级iOS安全框架:SSKeyChain   

详细介绍:http://blog.sina.com.cn/s/blog_93f39bc20101a44t.html


SSKeyChains对苹果安全框架API进行了简单封装,支持对存储在钥匙串中密码、账户进行访问,包括读取、删除和设置。SSKeyChain的作者是大名鼎鼎的SSToolkit的作者samsoffes

项目地址:https://github.com/samsoffes/sskeychain



获取uuid的两种方法:


一:钥匙串储存 就算程序被删除也能获取唯一标示  但是系统重装就不一定了 

+ (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;

}


二:程序的唯一标示  一旦程序被删除 标示也就跟着改变了

NSString *udid = [[UIDevice currentDevice].identifierForVendor UUIDString];





你可能感兴趣的:(获取iOS设备唯一标识 uuid)