swiftnsuserdefaultstestflight

Is there a way to use CFBundleShortVersionString to recognize new builds in Testflight?


We don't increment version number in our builds because that would trigger a TF review. So instead we leave it as the same version and xcode automatically increment the build number instead so it's 0.1 (5).

However, in our code we also check for version number to show popups unique to each release. Like this:

func getCurrentAppVersion() -> String {
    let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"]
    let version = (appVersion as! String)

    return version
}

We then save that to userdefaults and check it on launch.

Is there a way to make that work with the auto incremented number?


Solution

  • The build number is CFBundleVersion.

    Taking the sample you provided, this should demonstrate:

    // your code -> version number
            let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"]
            let version = (appVersion as! String)
    // value for build number
            let buildVersion = Bundle.main.infoDictionary?["CFBundleVersion"]
            let build = (buildVersion as! String)
    
    //display purposes only, in TestFlight format
            print (version, "(", build, ")", separator:"")
    

    If the Info.plist said:

        <key>CFBundleShortVersionString</key>
        <string>1.0</string>
        <key>CFBundleVersion</key>
        <string>1</string>
    

    The output would be 1.0 (1)

    (For the use case you described, pls. remember not compare as a String)