简体   繁体   English

以编程方式查找iPhone应用程序标识符前缀

[英]Finding iPhone Application Identifier Prefix programmatically

Is there any way to find the application identifier prefix in you iPhone application programmatically? 有没有办法以编程方式在iPhone应用程序中找到应用程序标识符前缀? Or even just to get the entire Application Identifier string? 或者甚至只是获取整个应用程序标识符字符串?

I see you can find it by peeking into the "embedded.mobileprovision" file, but is there an easier way? 我看到你可以通过窥视“embedded.mobileprovision”文件找到它,但有更简单的方法吗? (And I don't think that works if you're running in the simulator) (如果你在模拟器中运行,我认为这不起作用)

EDIT: Sorry, what I mean is the identifier PREFIX (10 characters). 编辑:对不起,我的意思是标识符PREFIX(10个字符)。 I've realized though that I don't actually need this, because the rest of the ID is guaranteed to be unique anyway. 我已经意识到我实际上并不需要这个,因为无论如何,ID的其余部分都保证是唯一的。

The bundle id is stored in the Info.plist of the app bundle as St3fan specified, but you should not grope at the Info.plist directly. bundle ID存储在应用程序包的Info.plist中,如St3fan所指定,但您不应直接在Info.plist上进行搜索。 Instead, use: 相反,使用:

[[NSBundle mainBundle] bundleIdentifier]

You can programmatically retrieve the Bundle Seed ID by looking at the access group attribute (ie kSecAttrAccessGroup ) of an existing KeyChain item. 您可以通过查看现有KeyChain项的访问组属性(即kSecAttrAccessGroup )以编程方式检索Bundle Seed ID。 In the code below, I look up for an existing KeyChain entry and create one if it doesn't not exist. 在下面的代码中,我查找现有的KeyChain条目,如果它不存在则创建一个。 Once I have a KeyChain entry, I extract the access group information from it and return the access group's first component separated by "." 一旦我有KeyChain条目,我从中提取访问组信息并返回访问组的第一个组件,以“。”分隔。 (period) as the Bundle Seed ID. (期间)作为捆绑种子ID。

+ (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;
}

If I understand correctly you are looking for bundle identifier? 如果我理解正确您正在寻找捆绑标识符? if you you can get this way. 如果你能得到这样的话。

NSString* appID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM