以编程方式访问应用程序标识符前缀 [英] Access App Identifier Prefix programmatically

查看:238
本文介绍了以编程方式访问应用程序标识符前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式存取Bundle种子ID / Team ID /应用程式识别码前置字串? (这些都是相同的东西,就我所知)。

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).

我使用UICKeychainStore钥匙扣包装器来保存数据跨多个应用程序。这些应用程序中的每一个在其授权列表中具有共享的密钥链访问组,并且共享相同的供应简档。默认情况下,钥匙串服务使用plist中的第一个访问组作为保存数据的访问组。这看起来像AS234SDG.com.myCompany.SpecificApp当我调试UICKeychainStore。我想将访问组设置为AS234SDG.com.myCompany.SharedStuff,但我似乎无法找到如何获得访问组的AS234SDG字符串编程,并希望避免硬编码如果可能的话。

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.

推荐答案

您可以通过查看访问组属性以编程方式检索Bundle种子ID(即 kSecAttrAccessGroup )。在下面的代码中,我查找一个现有的KeyChain条目并创建一个如果它不存在。一旦我有一个KeyChain条目,我从它提取访问组信息,并返回访问组的第一个组件分隔的。 (period)作为Bundle种子ID。

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 {
    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;
}

这篇关于以编程方式访问应用程序标识符前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆