You can programmatically retrieve the Bundle Seed ID by looking at the access group attribute (i.e.kSecAttrAccessGroup
) of an existing KeyChain item. In the code below, I look up for an existing KeyChain entry and create one if it doesn’t not exist. Once I have a KeyChain entry, I extract the access group information from it and return the access group’s first component separated by “.” (period) as the Bundle Seed ID.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
+ (NSString *)bundleSeedID { NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys: 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 = [(NSDictionary *)result objectForKey:kSecAttrAccessGroup]; NSArray *components = [accessGroup componentsSeparatedByString:@"."]; NSString *bundleSeedID = [[components objectEnumerator] nextObject]; CFRelease(result); return bundleSeedID; } |