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;
}
网友评论