How can I display the application version revision in my application's settings bundle?

前端 未结 13 717
一个人的身影
一个人的身影 2020-11-29 15:20

I would like to include the application version and internal revision, something like 1.0.1 (r1243), in my application\'s settings bundle.

The Root.plist file contai

相关标签:
13条回答
  • 2020-11-29 16:02

    The other answers do not work correctly for one reason: The run script build phase isn't executed until AFTER the Settings Bundle has been packaged. So, if your Info.plist version is 2.0.11 and you update it to 2.0.12, then build/archive your project, the Settings bundle will still say 2.0.11. If you open the Settings bundle Root.plist, you can see that the version number does not get updated until the END of the build process. You can build the project AGAIN to get the Settings bundle updated correctly, or you can add the script to a pre-build phase instead...

    • In XCode, Edit the Scheme for your project target
    • Click the disclosure arrow on the BUILD scheme
    • Then, click on the "Pre-actions" item
    • Click the plus sign and choose "New Run Script Action"
    • Set the shell value to /bin/sh
    • Set "Provide build settings from" to your project target
    • Add your script to the text area. The following script worked for me. You may need to modify the paths to match your project setup:

      versionString=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")

      /usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:0:DefaultValue $versionString"

    This will correctly run the script BEFORE the Settings bundle is packaged during the build/archive process. If you open the Settings bundle Root.plist and build/archive your project, you will now see the version number is updated at the beginning of the build process and your Settings bundle will display the correct version.

    0 讨论(0)
提交回复
热议问题