好吧,我也有这个问题。解决方案(某种程度上)是提供一个默认值字段并为其赋予一个值。这实际上在文档中明确说明 - 默认值是标题属性的必填字段,因此如果您不指定它,标题将不会显示在设置窗格中。不幸的是,一旦设置了该值,我似乎就无法更改该值,可能也是按照设计的——文档还指出它是只读属性。我要尝试的解决方案是每次进行新构建时都将版本号明确地放入我的 Root.plist 文件中。超级不理想,但我认为会起作用。
编辑:查看这篇关于更新设置包中版本号的文章 https://stackoverflow.com/a/1061864/1166029
编辑:好的,我得到了这个工作(感谢上面的那篇文章,以及对 bash 脚本的一些修改,我对此几乎没有经验。)这是脚本(我刚刚在“运行脚本”构建中内联编写)阶段):
#!/bin/bash
builtInfoPlistPath=${TARGET_BUILD_DIR}/${INFOPLIST_PATH}
#increment the build number
buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$builtInfoPlistPath")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$builtInfoPlistPath"
#compose the version number string
versionString=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$builtInfoPlistPath")
versionString+=" ("
versionString+=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$builtInfoPlistPath")
versionString+=")"
#write the version number string to the settings bundle
#IMPORTANT: this assumes the version number is the first property in the settings bundle!
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:0:DefaultValue $versionString" "Settings.bundle/Root.plist"
...就是这样!奇迹般有效!希望这对您的问题有所帮助,因为它解决了我的问题。现在唯一的问题是与内部版本号略有差异......
编辑:...我用它修复了vakio 对这篇文章的第二条评论 https://stackoverflow.com/a/4203459/1166029,它将 info.plist 的路径设置为已处理的路径(在运行脚本阶段之前!)
编辑:这是我的最新版本,它位于外部文件中,并在增加内部版本号之前验证某些源文件是否已更改:
#!/bin/bash
#note: for simplicity, it's assumed that there's already a bundle version (which is an integer) and a version string. set them in the Summary pane!
#get path to the BUILT .plist, NOT the packaged one! this fixes the off-by-one bug
builtInfoPlistPath=${TARGET_BUILD_DIR}/${INFOPLIST_PATH}
echo "using plist at $builtInfoPlistPath"
modifiedFilesExist=false
#this is the modification date to compare to -- there's a possible bug here, if you edit the built plist directly, for some reason. probably you shouldn't do that anyways.
compModDate=$(stat -f "%m" "$builtInfoPlistPath")
for filename in *
do
modDate=$(stat -f "%m" "$filename")
if [ "$modDate" -gt "$compModDate" ]
then
modifiedFilesExist=true;
echo "found newly modified file: $filename"
break
fi
done
if $modifiedFilesExist
then
echo "A file is new, bumping version"
#increment the build number
buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$builtInfoPlistPath")
echo "retrieved current build number: $buildNumber"
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$builtInfoPlistPath"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
#compose the version number string
versionString=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$builtInfoPlistPath")
versionString+=" ("
versionString+=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$builtInfoPlistPath")
versionString+=")"
#write the version number string to the settings bundle
#IMPORTANT: this assumes the version number is the second property in the settings bundle!
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue $versionString" "Settings.bundle/Root.plist"
else
echo "Version not incremented -- no newly modified files"
fi