You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

禁用IOS ATS后仍拦截HTTP请求,Cordova旧应用如何配置?

解决Cordova旧版iOS ATS允许任意HTTP请求的问题

检查ATS配置层级是否正确

ATS的所有配置必须嵌套在NSAppTransportSecurity顶级字典下,正确的Info.plist结构应该是:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>

如果你的配置直接放在Info.plist的根字典中,ATS规则不会生效。

不要直接修改Xcode的Info.plist(旧版Cordova关键)

旧版Cordova在构建时会根据config.xml重新生成Info.plist,直接修改Xcode项目里的文件会被覆盖。正确做法是在项目根目录的config.xml中添加配置:

  • 若Cordova版本≥6.0,使用edit-config标签:
<platform name="ios">
    <edit-config file="*-Info.plist" mode="merge" target="NSAppTransportSecurity">
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
            <key>NSAllowsArbitraryLoadsInWebContent</key>
            <true/>
        </dict>
    </edit-config>
</platform>
  • 若Cordova版本<6.0,使用config-file标签替代:
<platform name="ios">
    <config-file parent="NSAppTransportSecurity" target="*-Info.plist">
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </config-file>
</platform>

添加后执行cordova build ios,再打开Xcode项目确认Info.plist中的ATS配置是否正确生成。

排查配置冲突

如果之前添加过NSExceptionDomains配置,iOS会优先使用域名例外规则,即使开启了全局的NSAllowsArbitraryLoads。确保没有残留的NSExceptionDomains配置干扰全局规则。

适配iOS版本差异

  • iOS 9及以下:不存在NSAllowsArbitraryLoadsInWebContent,仅需将NSAllowsArbitraryLoads设为true即可。
  • iOS 10+:NSAllowsArbitraryLoads的优先级降低,需配合NSAllowsArbitraryLoadsInWebContent才能覆盖WKWebView的HTTP请求限制。

内容的提问来源于stack exchange,提问作者bramasta vikana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 00:52:40