好的,我也有这个问题。解决方案(有点)是提供一个默认值字段并给它一个值。这实际上在文档中明确说明 - 默认值是 Title 属性的必填字段,因此如果您不指定它,标题将不会显示在设置窗格中。不幸的是,一旦设置,我似乎无法更改值,也可能按设计 - 文档还指出它是只读属性。我要尝试的解决方案是在每次构建新版本时明确地将版本号放入我的 Root.plist 文件中。我认为超级不理想,但会起作用。
编辑:查看这篇关于更新设置包中的版本号的帖子
编辑:好的,我得到了这个工作(感谢上面的那个帖子,以及我对 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 对这篇文章的第二条评论进行了修复,而是将 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