繁体   English   中英

从iOS8上的Bundle ID获取应用程序名称

[英]Getting the name of an app from a Bundle ID on iOS8

我正在尝试使用以下代码:

NSString *appName = [[NSBundle bundleWithIdentifier:item] objectForInfoDictionaryKey:@"CFBundleExecutable"];

要从其捆绑标识符中获取应用程序名称,但是对于所有非库存应用程序,此方法返回nil。 我试图寻找解决此问题的方法。 如何从iOS 8中的捆绑包ID中获取应用程序的名称?

编辑:澄清一下,我想将其用于我自己以外的应用程序。

尝试这个

NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleExecutable"];

或者,如果您想更正确一点,请参考[NSBundle bundleForClass:[self class]]

但是,最好不要访问CFBundleName密钥,后者是应用程序图标下的名称,而不是访问CFBundleExecutable密钥。

NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSBundle *bundle = [NSBundle bundleWithIdentifier:bundleIdentifier];
NSString *appName = [bundle objectForInfoDictionaryKey:@"CFBundleExecutable"];
NSLog(@"%@", appName);

暂无
暂无

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

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