【问题标题】:How to read the Bundle version from PList?如何从 PList 中读取 Bundle 版本?
【发布时间】:2019-09-04 10:10:31
【问题描述】:

有没有办法读取应用程序捆绑的 plist 文件,我想提取 Bundle 版本的值。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    Getting the Bundle’s Info.plist Data

    [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
    

    应该给你捆绑版本。

    【讨论】:

    【解决方案2】:

    在 Swift 中你可以使用:

    let bundleVersion = Bundle.main.object(forInfoDictionaryKeykCFBundleVersionKey as String) as! String
    

    或:

    let bundleVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as! String
    

    如果你想要简短的捆绑版本字符串,你可以使用:

    let shortBundleVersion = Bundle.main.object(forInfoDictionaryKey:"CFBundleShortVersionString") as! String
    

    【讨论】:

      【解决方案3】:
      #define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] 
      

      【讨论】:

        猜你喜欢
        • 2011-05-18
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 2012-10-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多