在我的调试版本中,我想在Settings.bundle/Root.plist文件中显示一些设置。主要是,我想展示移动应用程序正在使用的后端环境,并使其为测试人员配置。
在我的发行版构建中,我希望将这些设置隐藏在Settings.bundle/Root.plist文件中,因为它总是指向生产。
如何在编译时修改Root.plist文件,因为无法在运行时修改该文件?
发布于 2016-04-22 05:18:29
在OS上,有一个名为PlistBuddy的命令,可以列出/更改.plist文件。
/usr/libexec/PlistBuddy
Usage: PlistBuddy [-cxh] <file.plist>
-c "<command>" execute command, otherwise run in interactive mode
-x output will be in the form of an xml plist where appropriate
-h print the complete help info, with command guide您可以使用自定义的MSBuild任务来使用-c "Add"或-c "Set"或-c "Delete"命令修改.plist,运行/usr/libexec/PlistBuddy -h以获得有关使用各种命令的帮助。
类似于从iOS项目根目录输出控制台上.plist格式的内容:
find . -name "Root.plist" | xargs -n 1 -J % /usr/libexec/PlistBuddy -x -c "Print" %<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Title</key>
<string>Debug Settings</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>1</string>
<key>FalseValue</key>
<string>0</string>
<key>Key</key>
<string>__monotouch_debug_enabled</string>
<key>Title</key>
<string>Enabled</string>
<key>TrueValue</key>
<string>1</string>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
</dict>
<dict>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
<key>DefaultValue</key>
<string>automatic</string>
<key>Key</key>
<string>__monodevelop_host</string>
<key>Title</key>
<string>Xamarin Studio Host</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
</array>
<key>StringsTable</key>
<string>Root</string>
<key>Title</key>
<string>AppSettings</string>
</dict>
</plist>https://stackoverflow.com/questions/36783856
复制相似问题