XCode 4:Insert Subversion revision number in Xcode

僤鯓⒐⒋嵵緔 提交于 2019-12-03 09:11:30

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"]

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.

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}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!