Skip to content

Instantly share code, notes, and snippets.

@hujunfeng
Last active September 30, 2022 20:40
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hujunfeng/8d609ec97c2403fd740d to your computer and use it in GitHub Desktop.
Add version in Settings.bundle for iOS apps
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>DefaultValue</key>
<string></string>
<key>Key</key>
<string>SNAppVersion</string>
<key>Title</key>
<string>Version</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
</array>
<key>StringsTable</key>
<string>Root</string>
</dict>
</plist>
#!/bin/bash
# Add a Run Script in Build Phase and put in the content of this script
PLISTBUDDY="/usr/libexec/PlistBuddy"
INFO_PLIST="$CODESIGNING_FOLDER_PATH/Info.plist"
SETTINGS_PLIST="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.plist"
VERSION_NUMBER="`$PLISTBUDDY -c \"Print CFBundleShortVersionString\" \"$INFO_PLIST\"`"
BUILD_NUMBER="`$PLISTBUDDY -c \"Print CFBundleVersion\" \"$INFO_PLIST\"`"
VERSION="$VERSION_NUMBER ($BUILD_NUMBER)"
$PLISTBUDDY -c "Set :PreferenceSpecifiers:0:DefaultValue '$VERSION'" "$SETTINGS_PLIST"
@mrvincenzo
Copy link

Thanks! Work great. Just keep in mind that the update_version_settings_bundle.sh assumes the Version preference is the first preference (Set :PreferenceSpecifiers:0:DefaultValue ...)

@mrvincenzo
Copy link

mrvincenzo commented Sep 30, 2022

A simplified version of the build phase

PLISTBUDDY="/usr/libexec/PlistBuddy"
SETTINGS_PLIST="${CODESIGNING_FOLDER_PATH}/Settings.bundle/Root.plist"
VERSION="$MARKETING_VERSION ($CURRENT_PROJECT_VERSION)"
$PLISTBUDDY -c "Set :PreferenceSpecifiers:0:DefaultValue '$VERSION'" "$SETTINGS_PLIST"

Reference: https://stackoverflow.com/a/58552727/396949

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