//获取唯一标识符 (依赖 KeychainItemWrapper)
- (NSString *)setUpUUID {
NSString *accessGroup = [self getAccesGroup];
KeychainItemWrapper *keyChainItem=[[KeychainItemWrapper alloc]initWithIdentifier:@"KCUUID" accessGroup:accessGroup];
NSString *strUUID = [keyChainItem objectForKey:(id)kSecValueData];
if (strUUID==nil||[strUUID isEqualToString:@""]) {
[keyChainItem setObject:[self gen_uuid] forKey:(id)kSecValueData];
}
return [keyChainItem objectForKey:(id)kSecValueData];
}
- (NSString *)gen_uuid {
CFUUIDRef uuid_ref=CFUUIDCreate(nil);
CFStringRef uuid_string_ref=CFUUIDCreateString(nil, uuid_ref);
CFRelease(uuid_ref);
NSString *uuid=[NSString stringWithString:(__bridge NSString * _Nonnull)(uuid_string_ref)];
CFRelease(uuid_string_ref);
return uuid;
}
- (NSString *)getAccesGroup {
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge NSString *)kSecClassGenericPassword, kSecClass,
@"bundleSeedID", kSecAttrAccount,
@"", kSecAttrService,
(id)kCFBooleanTrue, kSecReturnAttributes,
nil];
CFDictionaryRef result = nil;
OSStatus status = SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result);
if (status == errSecItemNotFound)
status = SecItemAdd((CFDictionaryRef)query, (CFTypeRef *)&result);
if (status != errSecSuccess)
return nil;
NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:(__bridge NSString *)kSecAttrAccessGroup];
CFRelease(result);
return accessGroup;
}