Skip to content

Instantly share code, notes, and snippets.

@hishma
Last active May 31, 2022 07:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hishma/4c872ab7e3ca1187c7f8 to your computer and use it in GitHub Desktop.
Save hishma/4c872ab7e3ca1187c7f8 to your computer and use it in GitHub Desktop.
Display iOS app version in settings

To display the current version of an iOS app in the settings

  1. Add an entry like this in Settings.bundle/Root.plist
<key>PreferenceSpecifiers</key>
<array>
  <dict>
    <key>Type</key>
    <string>PSTitleValueSpecifier</string>
    <key>Title</key>
    <string>Version</string>
    <key>Key</key>
    <string>version_preference</string>
    <key>DefaultValue</key>
    <string></string>
    </dict>
    ...
  </array>
  1. Add a new Run Script phase in the build phase to the target like this
cd $PROJECT_DIR
cd "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app"
RELEASE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" Info.plist)
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" Info.plist)
VERSION_STRING="$RELEASE_VERSION ($BUILD_NUMBER)"
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:0:DefaultValue $VERSION_STRING" Settings.bundle/Root.plist
@leanwebstart
Copy link

Worked like a charm in Xcode 12 ... Thank you!

@njoseph79
Copy link

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment