开发者

infoDictionary Build Number Not Synchronized With Plist

开发者 https://www.devze.com 2023-01-24 04:17 出处:网络
I followed this guide to implementing build numbers in an XCode iPhone project (guide). I tried it and I am getting the wrong build number when NSLogging. It\'s not updating correctly and is always on

I followed this guide to implementing build numbers in an XCode iPhone project (guide). I tried it and I am getting the wrong build number when NSLogging. It's not updating correctly and is always one or two numbers behind the info.plist. I need it to be the same number. Anyone know why this is happening?

i.e "[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBuildNumber"]" is not the same as the plist's CFBuildNumber.

The script is set to run first, before copy bundle resources and everything. This is the output and info.plist numbers I get:

Application Version: 1.0 Build No: 52 Build Date: Wed Nov 10 15:10:05 CET 2010

(info.plist is build number: 54 and date: Wed Nov 10 15:10:43 CET 2010)

Application Version: 1开发者_运维知识库.0 Build No: 54 Build Date: Wed Nov 10 15:10:43 CET 2010

(info.plist is build number: 55 and date: Wed Nov 10 15:12:54 CET 2010)

Application Version: 1.0 Build No: 54 Build Date: Wed Nov 10 15:10:43 CET 2010

(info.plist is build number: 56 and date: Wed Nov 10 15:13:49 CET 2010)

Application Version: 1.0 Build No: 56 Build Date: Wed Nov 10 15:13:49 CET 2010

(info.plist is build number: 57 and date:Wed Nov 10 15:14:46 CET 2010)

It seems to follow this pattern throughout. So continuing it would be 56 (real 58), 58 (real 59), 58 (real 60), 60 (real 61), 60 real (62), 62 (real 63) etc. etc.

The script (that is set to run before everything else) is:

#!/bin/bash
# Auto Increment Version Script
buildPlist="Project-Info.plist"
CFBuildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
CFBuildNumber=$(($CFBuildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $CFBuildNumber" $buildPlist
CFBuildDate=$(date)
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" $buildPlist


Because project's Info.plist processed prior to 'Run Script' phase. See 'Build results' window in XCode. To resolve this you should 1) Create new target with type "Run script only" and configure it to update version number 2) Create new target with type "Aggregate" and add to it "Version update" target and "you product" target.

So when you build "Aggregate" target, at first step - version will be updated, and at second step - your product.


I ended up using the already-copied plist file, ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}, and placing the "copy bundle resources"-phase before the script runs instead. That way the number will always be synchronized.

0

精彩评论

暂无评论...
验证码 换一张
取 消