infoDictionary Build Number Not Synchronized With Plist
Asked Answered
M

2

2

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
Mcneese answered 10/11, 2010 at 14:54 Comment(0)
M
0

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.

Mcneese answered 15/5, 2020 at 7:14 Comment(2)
Hi @Mcneese — with your experience from this question, I'm wondering if you have an answer for #69940117 ?Shack
@Shack Hello! Sorry, I only remember being frustrated with this and fiddling with it trial-and-error style until something just started working. I remember that it always seemed to edit the file correctly at first, but for some reason it was later overwritten by a ghost cached version...Mcneese
W
3

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.

Will answered 17/11, 2010 at 10:28 Comment(4)
Thanks but that's too many targets. I tried to point to another plist file that I add in the copy bundle phase and added 'touch -cm' in my run script to force Xcode to copy the file everytime but Xcode still does not copy the file half the time.Mcneese
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. But you lead me to it so I'ma give you props. Thanks.Mcneese
There is no need to create an aggregate target. When you show the information of any target, you can specify a "Direct dependency" and there you can include any other target there, which is run automatically before the selected target.So you only need a separate target for the shell script and include that as a direct dependency in all the others.Balancer
"1) Create new target with type "Run script only" and configure it to update version number" What is this? I don't see it in XCode 4.Neonatal
M
0

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.

Mcneese answered 15/5, 2020 at 7:14 Comment(2)
Hi @Mcneese — with your experience from this question, I'm wondering if you have an answer for #69940117 ?Shack
@Shack Hello! Sorry, I only remember being frustrated with this and fiddling with it trial-and-error style until something just started working. I remember that it always seemed to edit the file correctly at first, but for some reason it was later overwritten by a ghost cached version...Mcneese

© 2022 - 2024 — McMap. All rights reserved.