1

Yes, this is very related to this question, yet I think that question is adequately answered for XCode 3. Not sure if this should be merged or not.

So - Using similar instructions from there, I've long had the nice effect of having build numbers encoded into archived .ipa files, such that Organizer shows versions like "1.0.3281" (where 3281 is the revision via the below build script attached to my iOS target):

REV=`svnversion -nc | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'`
echo "REV=$REV"
echo "#define kRevisionNumber @\"$REV\"" > ${PROJECT_DIR}/revision.h
echo "INFOPLIST_PATH=${INFOPLIST_PATH}"

BASEVERNUM=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${INFOPLIST_FILE}" | sed 's/,/, /g'`
echo "BASEVERNUM=$BASEVERNUM"
PLISTARG1="Set :CFBundleVersion $BASEVERNUM.$REV"
echo "PLISTARG1=$PLISTARG1"

/usr/libexec/PlistBuddy -c "$PLISTARG1" "${TARGET_BUILD_DIR}"/${INFOPLIST_PATH}

However, XCode 4 (which I've since come to love) clearly needs some tweaking, as this magic only sort-of works. Here is the result of the scripts above.

REV=3281
INFOPLIST_PATH=Foo.app/Info.plist
BASEVERNUM=1.0
PLISTARG1=Set :CFBundleVersion 1.0.3281

And I can see by looking in ~/Library/.../Foo.app/Info.plist that yes, it did update the right version:

<key>CFBundleVersion</key>
<string>1.0.3281</string>

So clearly there is an additional file needing updating.. perhaps in the .xcarchive? Any suggestions on where to drill into first?

Community
  • 1
  • 1
Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43

3 Answers3

5

I'm not sure about the archive angle, but the following is working for me in Xcode 4 (i.e. my app is listed in organiser as Foo 1.0.307)

  1. Manually set the CFBundleShortVersionString (aka "Bundle versions string, short") value in your info.plist to your major.minor build number (e.g. 1.0)

  2. Add a 'run script' build phase to your project with the following script

    REV=`svnversion -nc | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'`
    BASEVERNUM=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${INFOPLIST_FILE}"`
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BASEVERNUM.$REV" "${INFOPLIST_FILE}"
    
  3. Clean and build (the Clean step forces Xcode to reprocess the info.plist).

BTW you can also access this version number inside your app (e.g. on your 'about' page) using [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]

Jaysen Marais
  • 3,956
  • 28
  • 44
  • Alas, it is exactly the archiving that I'm looking for to work, that still does work in XCode 3 which now doesn't seem to in 4. Appreciate your suggestions though Jaysen. Thanks. – Scott Corscadden Jun 29 '11 at 17:07
  • Hi Jaysen, works like a charm, but this script will of course change your info plist, which you should commit, which causes a change, which you should commit, etc. etc. Maybe it's better to build something like this as a svn or git commit hook? http://svnbook.red-bean.com/en/1.2/svn.reposadmin.create.html#svn.reposadmin.create.hooks – Johan Pelgrim Dec 13 '11 at 11:34
  • doesnt work at all since the path is wrong. Put a working version below. @JohanPelgrim yes might be better but im too lazy – Daij-Djan Sep 04 '13 at 11:39
0

will show in organizer BUT your plist needs a DDBundleBaseVersion key (a key I made up. it should hold the original value of the ShortVersionString)

PLIST=${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH};
REV=`svnversion -nc | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'`
BASEVERNUM=`/usr/libexec/PlistBuddy -c "Print :DDBundleBaseVersion" "${PLIST}"`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BASEVERNUM.$REV" "${PLIST}"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $BASEVERNUM.$REV" "${PLIST}"

wont show in organizer but will work fine:

PLIST=${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH};
REV=`svnversion -nc | /usr/bin/sed -e 's/^[^:]*://;s/[A-Za-z]//'`
BASEVERNUM=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${PLIST}"`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BASEVERNUM.$REV" "${PLIST}"
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
0

If your script update both fields CFBundleVersion and CFBundleShortVersionString then .xcarchive will show you correct version

But may be you find better way? Way without updating CFBundleShortVersionString is appreciated.

Maxim Kholyavkin
  • 4,463
  • 2
  • 37
  • 82