MrB*_*rBr 17 xml objective-c ios
我只想在设置文件中输出我的ios应用程序的版本号.
我知道我必须将设置文件添加到应用程序文件夹中.
当我构建并运行时,我可以看到标准设置包附带的4个设置.
为了获得一个简单的只读字符串,我将第二个值更改为以下值

在代码(didFinishLaunchingWithOptions :)中,我调用以下内容:
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
[[NSUserDefaults standardUserDefaults] setValue:version forKey:@"version_number"];
[[NSUserDefaults standardUserDefaults] synchronize];
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,没有任何事情发生.我只看到Group元素和toogle开关和滑块但没有标题行.谁知道我错过了什么?
非常感谢你!
sas*_*ash 26
我遇到过同样的问题.要显示标题属性,Settings.bundle您还需要添加"默认值"(它可能为空).
1)右键单击Title对象(在我的例子中是Item 0)并选择Add Row.
2)在创建的行的下拉列表中选择"默认值"

3)在要显示的didFinishLaunchingWithOptions设定值中NSUserDefaults,例如:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"0.0.1" forKey:@"appVersion"];
[defaults synchronize];
Run Code Online (Sandbox Code Playgroud)
结果:

sam*_*son 24
好的,我也有这个问题.解决方案(类型)是提供默认值字段并给出一个值.这实际上在文档中明确说明 - 默认值是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"
Run Code Online (Sandbox Code Playgroud)
......就是这样!奇迹般有效!希望有助于解决你的问题,因为它解决了我的问题.现在唯一的问题是与内部版本号略有差异......
编辑:...我用vakio对这篇文章的第二条评论进行了修改,它将info.plist的路径设置为已经处理的路径(在Run Script阶段之前!)
编辑:这是我的更新版本,它位于外部文件中,并在增加内部版本号之前验证某些源文件是否已更改:
#!/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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13451 次 |
| 最近记录: |