从iOS8上的bundleID中获取应用程序的名称



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

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

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

编辑:为了澄清,我想把它用于我自己的应用程序之外的其他应用程序。

试试这个

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

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

但是,与其访问CFBundleExecutable密钥,不如访问CFBundleName键,它是应用程序图标下的名称。

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

最新更新