首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin和iOS:在编译时修改Root.plist

Xamarin和iOS:在编译时修改Root.plist
EN

Stack Overflow用户
提问于 2016-04-22 02:40:58
回答 1查看 335关注 0票数 0

在我的调试版本中,我想在Settings.bundle/Root.plist文件中显示一些设置。主要是,我想展示移动应用程序正在使用的后端环境,并使其为测试人员配置。

在我的发行版构建中,我希望将这些设置隐藏在Settings.bundle/Root.plist文件中,因为它总是指向生产。

如何在编译时修改Root.plist文件,因为无法在运行时修改该文件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-22 05:18:29

在OS上,有一个名为PlistBuddy的命令,可以列出/更改.plist文件。

代码语言:javascript
复制
/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格式的内容:

代码语言:javascript
复制
find . -name "Root.plist" | xargs -n 1 -J % /usr/libexec/PlistBuddy -x -c "Print" %
代码语言:javascript
复制
<?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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36783856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档