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

使用Firebase Functions模拟器遇ATS错误,如何禁用SSL?

解决Firebase Functions模拟器的App Transport Security错误

这个错误是因为iOS的App Transport Security(ATS)默认强制所有网络请求使用HTTPS加密连接,但本地Firebase Functions模拟器使用的是HTTP协议,因此触发了ATS的限制。以下是具体解决步骤:

iOS 端配置修改

打开Flutter项目中ios/Runner目录下的Info.plist文件,添加ATS例外配置:

方式一:仅允许localhost的HTTP请求(推荐)

这种方式只针对本地模拟器域名放行,不会影响其他HTTPS请求,更安全:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>

方式二:临时禁用所有ATS限制(仅开发环境用)

如果只是开发测试阶段,可以快速禁用所有ATS限制,但正式发布APP前必须删除此配置:

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

代码优化建议

为了避免在生产环境误启用模拟器,建议只在调试模式下调用useFunctionsEmulator:

import 'package:flutter/foundation.dart';

// ...

if (kDebugMode) {
  FirebaseFunctions.instance.useFunctionsEmulator("localhost", 5001);
}

var result = FirebaseFunctions.instance
    .httpsCallable("checkVoucherCode")
    .call({"voucher_id": id})
    .then((value) {
  inspect(value);
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 18:01:20