【问题标题】:iOS Pre-build action to change plist value based on SchemeiOS Pre-build 动作来改变基于 Scheme 的 plist 值
【发布时间】:2017-09-19 18:42:37
【问题描述】:

我有一个 iOS 应用程序,它使用 Agentry 框架来定义要连接的 Agentry 服务器 URL。根据 SAP 规范,agentryServerURL 参数包含在单独的 branding.plist 文件中。我想要做的是将不同环境的 iOS 方案绑定到预构建操作,以更改代理 URL 值。

这是我当前的脚本,但它不起作用。

#!/bin/sh

plist=$SRCROOT"/branding.plist"

if [ ${CONFIGURATION} = "DEV" ]; then
/usr/libexec/PlistBuddy -c "Set :agentryServerURL https://smpdevURL" "$plist"

if [ ${CONFIGURATION} = "QA" ]; then
/usr/libexec/PlistBuddy -c "Set :agentryServerURL https://smpqaURL" "$plist"

if [ ${CONFIGURATION} = "Release" ]; then
/usr/libexec/PlistBuddy -c "Set :agentryServerURL https://smpprodURL" "$plist"
    fi

这是我第一次编写预构建脚本,所以它可能与我的语法有关

【问题讨论】:

    标签: ios xcode sh pre-build-event


    【解决方案1】:

    试试这个:

    #!/bin/sh
    
    plist="${SRCROOT}/branding.plist"
    
    if [ "${CONFIGURATION}" == "DEV" ]; then
    /usr/libexec/PlistBuddy -c "Set :agentryServerURL https://smpdevURL" "$plist"
    elif [ "${CONFIGURATION}" == "QA" ]; then
    /usr/libexec/PlistBuddy -c "Set :agentryServerURL https://smpqaURL" "$plist"
    elif [ "${CONFIGURATION}" == "Release" ]; then
    /usr/libexec/PlistBuddy -c "Set :agentryServerURL https://smpprodURL" "$plist"
    fi
    

    【讨论】:

    • 这不起作用,我意识到的一个区别是我的配置实际上是 Debug/QA/Release 所以我在 IF 语句中更改了它,但仍然没有运气。我需要做些什么来安装 plistbuddy?
    • 嗯,当我将它设置为目标的脚本构建阶段时,它对我有用。与您的原始文件一样,它要求您要更改的 plist 已经与您的项目文件位于同一目录中,并且您要更改的密钥存在于其中。因此,plist 的顶层应该是根字典,然后你应该有一个带有字符串值的 agentryServerURL 键。你有吗?
    • 问题是我没有选择“提供构建设置”值。
    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多