How do I get the current version of my iOS project in code?

后端 未结 8 1328
挽巷
挽巷 2020-12-12 10:23

I would like to be able to get the current version of my iOS project/app as an NSString object without having to define a constant in a file somewhere. I don\'t

8条回答
  •  感情败类
    2020-12-12 10:50

    Here's what worked on Xcode 8, Swift 3:

    let gAppVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") ?? "0"
    let gAppBuild = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") ?? "0"
    
    print("Version: \(gAppVersion)")
    print("Build: \(gAppBuild)")
    

提交回复
热议问题