您可以通過查看現有KeyChain項目的訪問組屬性(即kSecAttrAccessGroup
)以編程方式檢索Bundle Seed ID。在下面的代碼中,我查找現有的KeyChain條目並創建一個,如果它不存在。一旦我有一個KeyChain條目,我從它提取訪問組信息並返回由「。」分隔的訪問組的第一個組件。 (期間)作爲捆綁種子ID。
+ (NSString *)bundleSeedID {
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge NSString *)kSecClassGenericPassword, (__bridge NSString *)kSecClass,
@"bundleSeedID", kSecAttrAccount,
@"", kSecAttrService,
(id)kCFBooleanTrue, kSecReturnAttributes,
nil];
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;
NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:(__bridge NSString *)kSecAttrAccessGroup];
NSArray *components = [accessGroup componentsSeparatedByString:@"."];
NSString *bundleSeedID = [[components objectEnumerator] nextObject];
CFRelease(result);
return bundleSeedID;
}
我不知道如果我理解你,但它是這樣的NSString * bundleIDStr = [[[一個NSBundle mainBundle] infoDictionary] objectForKey:@ 「CFBundleIdentifier」];你在找什麼? – msk 2012-07-30 17:42:09
這將返回「com.myCompany.SpecificApp」 - 我正在查找「AS234SDG」前綴。 – 2012-07-30 17:52:16
哦,我有你現在問的問題... – msk 2012-07-30 17:55:01