How do I get the App version and build number using Swift?

前端 未结 30 978
暖寄归人
暖寄归人 2020-12-22 15:21

I have an IOS app with an Azure back-end, and would like to log certain events, like logins and which versions of the app users are running.

How can I return the ver

30条回答
  •  自闭症患者
    2020-12-22 15:38

    For Swift 3.0 NSBundle doesn't work, Following code works perfectly.

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

    and for just the build number, it is:

    let buildNumberString =
          Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")
              as! String
    

    Confusingly 'CFBundleVersion' is the build number as entered in Xcode on General->Identity.

提交回复
热议问题