ios - Phonegap修改NSAppTransportSecurity的config.xml

标签 ios xml cordova plist

我有一个下一个问题,我必须将 NSAppTransportSecurity key 添加到我的 info.plist 文件中。

因为我有许多不同的 config.xml 用于测试、开发和生产服务器,所以手动将 NSAppTransportSecurity key 添加到 plist 中是不好的。

这可以在 config.xml 本身内部完成吗?

我已经尝试过这个:

<manifest device="ios" tag="plist/dict">
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
        ...
        </dict>
    </array>

    <!--Here is my own:-->
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
</manifest>

但是在 cordova 构建 iOS 后,我在 info.plist 中得到了这个:

<key>[object Object]</key>
<string>NSAppTransportSecurity</string>

但是 CFBundleURLTypes 可以正常移植。我做错了什么?

最佳答案

您可以使用cordova-custom-config插件来实现这一点:

$ cordova plugin add cordova-custom-config

然后添加到config.xml:

<platform name="ios">
    <config-file platform="ios" target="*-Info.plist" parent="NSAppTransportSecurity">
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </config-file>
</platform>

关于ios - Phonegap修改NSAppTransportSecurity的config.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37851261/

相关文章:

ios - 为什么 MKMapView 不在初始应用程序启动时加载叠加层?

html to excel - 在每一页上打印第 1 行

java - JAXP 与 XSD import ArrayIndexOutOfBoundsException

iOS NativeControls - showToolBarTitle() 不工作 (PhoneGap)

cordova - Phonegap 原生通知声音

ios - 滚动后 UITableViewCell 中的 UIView 中的渐变发生变化

ios - 排序字母数字数组,连续的数字应该在最后

ios - 带阴影的 UIView - 应用 renderInContext 时速度较慢

php - 生成 XML 并将其保存到磁盘问题

ios - Cordova 应用程序外部链接在 iOS 上不起作用