infoDictionary Build Number Not Synchronized With

2019-04-14 04:02发布

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

1条回答
可以哭但决不认输i
2楼-- · 2019-04-14 04:51

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.

查看更多
登录 后发表回答