Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access App Identifier Prefix programmatically

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 UICKeychainStore keychain wrapper to persist data across several applications. Each of these applications has a shared keychain access group in their entitlement plists, and share the same provisioning profile. By default, the keychain services use the first access group in the plist as the access group to save data to. This looks like "AS234SDG.com.myCompany.SpecificApp" when I debug UICKeychainStore. I would like to set the access group to "AS234SDG.com.myCompany.SharedStuff", but I can't seem to locate how to get the "AS234SDG" string of the access group programmatically, and would like to avoid hard-coding it if possible.

like image 993
Jacob Jennings Avatar asked Jul 30 '12 17:07

Jacob Jennings


People also ask

How do I find my app ID prefix?

Log in to the iOS developer member center and navigate to "Certificates, Identifiers & Profiles". Once in there, navigate into the App IDs section inside of the Identifiers section. Create a new App ID with the same wildcard bundle ID you are already using but using your Team ID based prefix as its prefix.

What is Appid in swift?

An App ID is a two-part string used to identify one or more apps from a single development team. The string consists of a Team ID and a bundle ID search string, with a period ( . ) separating the two parts.


2 Answers

Info.plist can have your own information and if you write a value with $(AppIdentifierPrefix), it is replaced to the real app identifier prefix at building phase.

So, try this:

In your Info.plist, add an info about app identifier prefix.

<key>AppIdentifierPrefix</key> <string>$(AppIdentifierPrefix)</string> 

You can then retrieve it programmatically with Objective-C:

NSString *appIdentifierPrefix =     [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppIdentifierPrefix"]; 

and with Swift:

let appIdentifierPrefix =     Bundle.main.infoDictionary!["AppIdentifierPrefix"] as! String 

Note that appIdentifierPrefix ends with a period; e.g. AS234SDG.

like image 164
Hiron Avatar answered Oct 07 '22 18:10

Hiron


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; } 
like image 42
David H Avatar answered Oct 07 '22 19:10

David H