获取iOS设备唯一标识 uuid

时间:2025-01-29 22:36:46

获取uuid


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

详细介绍:/s/blog_93f39bc20101a44t.html


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

项目地址:/samsoffes/sskeychain



获取uuid的两种方法:


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

+ (NSString *)getDeviceId

{

    NSString * currentDeviceUUIDStr = [SSKeychain passwordForService:@" " account:@"uuid"];

    if (currentDeviceUUIDStr == nil || [currentDeviceUUIDStr isEqualToString:@""])

    {

        NSUUID * currentDeviceUUID  = [UIDevice currentDevice].identifierForVendor;

        currentDeviceUUIDStr = ;

        currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];

        currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];

        [SSKeychain setPassword: currentDeviceUUIDStr forService:@" " account:@"uuid"];

    }

    return currentDeviceUUIDStr;

}


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

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