【问题标题】:Get app name from bundle id从 bundle id 获取应用名称
【发布时间】:2012-12-24 16:22:18
【问题描述】:

我有来自设备上安装的应用程序的捆绑 ID 的列表,我想获取应用程序名称。解决方案应该适用于未越狱的设备。该应用不会在应用商店上架,因此不会出现应用拒绝。


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

【问题讨论】:

    标签: iphone objective-c ios


    【解决方案1】:

    大多数时候,你可以得到这个......

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

    编辑:

    您想为所有应用程序查找。

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

    【讨论】:

    • 是的,但此独奏仅适用于当前应用程序。
    • 你想要所有的应用程序?
    • 是的,这个想法是发现设备上所有已安装的应用程序,我想出了如何找到捆绑包,所以我需要显示名称。
    • 查看编辑:适用于所有应用
    • @Imran:我认为这是不可能的。
    【解决方案2】:

    应该这样做。

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

    方法

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

    【讨论】:

      【解决方案3】:

      我将捆绑字典设置如下:

      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
      • 这对我来说很好用。只是语法中的一个错字: NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary];
      【解决方案4】:

      如果您想获得本地化的包显示名称,请使用localizedInfoDictionary

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

      【讨论】:

        【解决方案5】:

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

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

        【讨论】:

          【解决方案6】:

          斯威夫特:

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

          【讨论】:

            【解决方案7】:
            NSString *appName = [[bundleID componentsSeparatedByString:@"."] lastObject];
            

            假设 bundleID 是反向 dns 格式..

            【讨论】:

            • 这不是很聪明,因为 BundleID 可以完全不同。
            • 更不用说不包含空格或特殊字符。
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-07-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-06-22
            相关资源
            最近更新 更多