获取应用程序名称的方法(从包标识符)

17

我有一个装在设备上的应用程序包 ID 列表,我想要获取相应的应用程序名称。解决方案应该可以在未越狱设备上运行。因为该应用程序不会发布到应用商店,所以应用程序拒绝并不重要。


我找到了这个解决方案,如果应用程序位于应用商店中,它将返回应用程序的详细信息。 http://itunes.apple.com/lookup?bundleId=com.bundle.id

7个回答

28

大部分时间,你可以通过这个来解决问题...

NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleNameKey];

编辑:

由于您想找到所有的应用程序。

NSString *appName = [[NSBundle bundleWithIdentifier:@"BundleIdentifier"] objectForInfoDictionaryKey:(id)kCFBundleExecutableKey];
NSLog(@"AppName: %@",appName);

是的,但这个解决方案仅适用于当前应用程序。 - Ivan Alek
请注意,CFBundleDisplayName 是应用程序在主屏幕等位置显示的实际人性化名称。 - devios1
有一个针对此的键:kCFBundleNameKey。无需硬编码键。 - pronebird
@AnoopVaidya...我们能否从包标识获取应用程序ID。假设我拥有所有已安装应用程序的包标识,并且我想要获取所有应用程序的应用程序ID,或者如果可能的话,使用包标识或应用程序名称获取所有应用程序的应用程序图标。 - Imran
2
@Imran: 我认为这是不可能的。 - Anoop Vaidya
显示剩余3条评论

11

这样就可以了。

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

方法

- (NSString *)titleOfAppWithBundleIdentifier:(NSString *)bundleIdentifier {
    NSBundle *bundle = [NSBundle bundleWithIdentifier:bundleIdentifier];
    return [bundle objectForInfoDictionaryKey:@"CFBundleExecutable"];
}

10

我将bundle字典设置如下:

NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary];

NSString *appName = [bundleInfo objectForKey:@"CFBundleDisplayName"];

这里是 bundleInfo 的转储:

{
    BuildMachineOSBuild = ...;
    CFBundleDevelopmentRegion = ...;
    CFBundleDisplayName = ...;
    CFBundleExecutable = ...;
    CFBundleIcons = {
        CFBundlePrimaryIcon = {
        CFBundleIconFiles = (
            "AppIcon29x29.png",
            "AppIcon29x29@2x.png",
            "AppIcon40x40@2x.png",
            "AppIcon57x57.png",
            "AppIcon57x57@2x.png",
            "AppIcon60x60@2x.png",
            "AppIcon60x60@3x.png"
        );
        UIPrerenderedIcon = 1;
       };
    };
    CFBundleIdentifier = ...;
    CFBundleInfoDictionaryVersion = ...;
    CFBundleInfoPlistURL = ...;
    CFBundleName = ...;
    CFBundleNumericVersion = 0;
    CFBundlePackageType = APPL;
    CFBundleShortVersionString = ...;
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneOS
    );
    CFBundleVersion = "1.0.11";
    DTCompiler = ...;
    DTPlatformBuild = ...;
    DTPlatformName = iphoneos;
    DTPlatformVersion = "8.3";
    DTSDKBuild = ...;
    DTSDKName = "iphoneos8.3";
    DTXcode = ...;
    DTXcodeBuild = ...;
    LSRequiresIPhoneOS = 1;
    MinimumOSVersion = "5.1";
    UIBackgroundModes =     (
        ...,
        ...
    );
    UIDeviceFamily =     (
        1
    );
    UILaunchImageFile = LaunchImage;
    UILaunchImages =     (
            {
            UILaunchImageMinimumOSVersion = "7.0";
            UILaunchImageName = ...;
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{320, 568}";
        }
    );
    UIMainStoryboardFile = Main;
    UIRequiredDeviceCapabilities =     (
        armv7
    );
    UISupportedInterfaceOrientations =     (
        UIInterfaceOrientationPortrait
    );
    UIViewControllerBasedStatusBarAppearance = 0;
}

这对我返回 nil。 - André Fratelli
1
这对我来说很好用。你的语法只是一个笔误: NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary]; - Shubham1164

2

如果您想获取本地化捆绑显示名称,请使用localizedInfoDictionary

NSString *appName = [[NSBundle mainBundle] localizedInfoDictionary][@"CFBundleDisplayName"];

0

我相信这应该能给你答案:

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

0

Swift:

if let bundle = Bundle(identifier: "com.my.bundleId"),
    let name = bundle.object(forInfoDictionaryKey: kCFBundleNameKey as String) {
    print(name)
}

-3
NSString *appName = [[bundleID componentsSeparatedByString:@"."] lastObject];

假设bundleIDs采用反向DNS格式..


9
这并不是明智之举,因为BundleID可能完全不同。 - IluTov
不要包含空格或特殊字符。 - devios1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接