[英]Getting the name of an app from a Bundle ID on iOS8
I'm trying to use this code: 我正在尝试使用以下代码:
NSString *appName = [[NSBundle bundleWithIdentifier:item] objectForInfoDictionaryKey:@"CFBundleExecutable"];
To get the name of an app from its Bundle Identifier, however for all non-stock apps this method is returning nil. 要从其捆绑标识符中获取应用程序名称,但是对于所有非库存应用程序,此方法返回nil。 I have tried to look for ways to solve this to no avail. 我试图寻找解决此问题的方法。 How can I get the name of an app from the bundle ID in iOS 8? 如何从iOS 8中的捆绑包ID中获取应用程序的名称?
EDIT: To clarify, I want to use this for apps other than my own. 编辑:澄清一下,我想将其用于我自己以外的应用程序。
Try this 尝试这个
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleExecutable"];
Or if you want to be a bit more correct, reference [NSBundle bundleForClass:[self class]]
或者,如果您想更正确一点,请参考[NSBundle bundleForClass:[self class]]
However, instead of accessing the CFBundleExecutable key, you are better off accessing the CFBundleName key instead, which is the name under your apps icon. 但是,最好不要访问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.