infoDictionary Build Number Not Synchronized With Plist

99封情书 提交于 2019-12-21 21:03:04

问题


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:


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.



来源:https://stackoverflow.com/questions/4145733/infodictionary-build-number-not-synchronized-with-plist

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