Access App Identifier Prefix programmatically

前端 未结 5 802
死守一世寂寞
死守一世寂寞 2020-11-28 20:15

How can I access the Bundle Seed ID/Team ID/App Identifier Prefix string programmatically? (These are all the same thing as far as I can tell).

I am using the UICKe

5条回答
  •  粉色の甜心
    2020-11-28 21:10

    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.

    + (NSString *)bundleSeedID {
        NSString *tempAccountName = @"bundleSeedID";
        NSDictionary *query = @{
            (__bridge NSString *)kSecClass : (__bridge NSString *)kSecClassGenericPassword,
            (__bridge NSString *)kSecAttrAccount : tempAccountName,
            (__bridge NSString *)kSecAttrService : @"",
            (__bridge NSString *)kSecReturnAttributes: (__bridge NSNumber *)kCFBooleanTrue,
        };
        CFDictionaryRef result = nil;
        OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
        if (status == errSecItemNotFound)
            status = SecItemAdd((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
        if (status != errSecSuccess) {
            return nil;
        }
        status = SecItemDelete((__bridge CFDictionaryRef)query); // remove temp item
        NSDictionary *dict = (__bridge_transfer NSDictionary *)result;
        NSString *accessGroup = dict[(__bridge NSString *)kSecAttrAccessGroup];
        NSArray *components = [accessGroup componentsSeparatedByString:@"."];
        NSString *bundleSeedID = [[components objectEnumerator] nextObject];
        return bundleSeedID;
    }
    

提交回复
热议问题