6

We'd like to put the current version of the app as a string in the bottom of our options in Settings.app, as a section footer.

I haven't worked with build scripts in Xcode very much, so i need some help on

  1. how to fetch the current version, probably from the info.plist
  2. how to replace a static string, for example CURRENT_VERSION_NO in the Root.plist inside the Settings.bundle

Thanks Maciej.

Bot
  • 11,868
  • 11
  • 75
  • 131
Maciej Swic
  • 11,139
  • 8
  • 52
  • 68
  • possible duplicate of [Xcode: Better way of incrementing build number?](http://stackoverflow.com/questions/9258344/xcode-better-way-of-incrementing-build-number) – Bo Persson Jul 23 '12 at 22:03
  • I am using the solution explained in the following stackoverflow question of mine: http://stackoverflow.com/questions/9258344/xcode-better-way-of-incrementing-build-number And have had no issues with it for many, many months. – trojanfoe Jul 23 '12 at 20:57

1 Answers1

5

You can add a run script phase for your target (build phases > add build phase > add run script). Then you will have a shell script where you could use PlistBuddy to get the version string and set it in your other plist.

For example :

/usr/libexec/PlistBuddy -c "print:CFBundleVersion" "$CONFIGURATION_BUILD_DIR/$INFOPLIST_PATH"

will display the version string of your app. If you record this in a variable and set the value on the other plist using Plist Buddy -c set, you will be done.

This would give something like :

versionString=$(/usr/libexec/PlistBuddy -c "print:CFBundleVersion" "$CONFIGURATION_BUILD_DIR/$INFOPLIST_PATH")
/usr/libexec/PlistBuddy -c "Set CURRENT_VERSION_NO $versionString" "$THE_PATH_TO_YOUR_PLIST_FILE"

I never used PlistBuddy -c copy but it should allow you to do this in only one line.

iDou
  • 767
  • 7
  • 6