美文网首页iOS 开发 深入浅出iOSiOS零碎知识
iOS获取唯一UUID/UDID的解决方案

iOS获取唯一UUID/UDID的解决方案

作者: 小码农_gjw | 来源:发表于2016-06-14 17:37 被阅读1696次

SFHFKeychainUtils (点击下载)是一个封装了KeyChain简单操作的第三方类库

1、引入Security.frameWork框架。

2、引入头文件:SFHKeychainUtils.h.(注意:SFHKeychainUtils为MRC,在ARC环境需配置如下)


3、方法如下

#pragma mark -获取唯一UUID

- (NSString*)UUID {

     NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];

     NSString *userName = infoDict[@"CFBundleName"];

     NSString *serviceName = infoDict[@"CFBundleIdentifier"];

     NSString *UUID = [SFHFKeychainUtils getPasswordForUsername:userName         andServiceName:serviceName error:nil];

     if (UUID.length==0) {

          UUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

          [SFHFKeychainUtils storeUsername:userName andPassword:UUID forServiceName:serviceName updateExisting:1 error:nil];

      }

         returnUUID;

}

相关文章

网友评论

    本文标题:iOS获取唯一UUID/UDID的解决方案

    本文链接:https://www.haomeiwen.com/subject/scyudttx.html