phonegap修改config.xml,用于NSApptransportSecurity



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

因为我有许多不同的config.xml用于测试,开发和生产服务器,因此将nsapptransportsecurity键手动添加不好。

可以在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之后,我在我的信息中得到了此信息。

<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>

我确实同意DeveAlden的解决方案。但是,如果NSAppTransportSecurity是您唯一有兴趣在*-Info.plist文件中操纵的东西,那么您可以使用Cordova-ios-Security插件

此插件会照顾您在*-Info.plist文件中手动做的工作

最新更新