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

Flutter iOS应用断开连接后重启崩溃问题求助

Flutter应用在iPhone 14断开电脑后重启崩溃,伴随Firebase配置警告

问题概述

  • 模拟器运行正常
  • iPhone 14连接电脑时启动正常,断开USB连接后重启应用立即崩溃
  • 设备启动时输出以下警告信息:
Runner[2706:915965] 10.7.0 - [FirebaseCore][I-COR000005] No app has been configured yet.
[TraitCollection] Class CKBrowserSwitcherViewController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.

已尝试的操作

  • 在main.dart中先执行WidgetsFlutterBinding.ensureInitialized()再初始化Firebase,警告仍存在
  • 删除并通过Xcode重新添加GoogleService-Info.plist
  • 将Xcode Scheme从Debug切换为Release,问题未解决

环境信息

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.11, on macOS 13.4.1 22F82 darwin-arm64, locale fr-BE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] Connected device (4 available)
    ! Error: Apple Watch de Bernard needs to connect to determine its availability. Check the connection between the device and its companion iPhone, and the connection between
      the iPhone and Xcode. Both devices may also need to be restarted and unlocked. (code 1)
[✓] HTTP Host Availability

• No issues found!

解决方案

1. 修复Firebase配置问题

  • 确认GoogleService-Info.plist已添加到Xcode的Runner目标中,且勾选了对应的Target Membership(在Xcode右侧面板查看)
  • 调整main函数的初始化逻辑,确保Firebase初始化完成后再启动应用:
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 针对Flutter 3.7+,使用DefaultFirebaseOptions自动加载平台配置
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}
  • 核对Firebase控制台中iOS应用的Bundle ID与项目Info.plist里的CFBundleIdentifier完全一致,包括大小写

2. 处理CKBrowserSwitcherViewController警告

该警告通常来自依赖的第三方SDK(如Firebase Auth、支付类SDK),可尝试:

  • 更新所有Flutter依赖插件到最新版本,尤其是Firebase相关插件(firebase_core、firebase_auth等)
  • 在Xcode中执行Product > Clean Build Folder清理缓存,然后重新构建项目

3. 定位崩溃根源

  • 重新连接iPhone到电脑,通过Xcode的Window > Devices and Simulators,选择对应设备后查看View Device Logs,找到崩溃的具体堆栈信息(这是解决崩溃最关键的步骤,当前警告可能只是关联现象)
  • 确认Release模式下,Info.plist中已正确声明所有必要权限(如网络访问NSAppTransportSecurity、通知权限等)

4. 其他排查步骤

  • 临时移除非必要的Flutter插件,逐一排查是否存在插件兼容性问题
  • 重启iPhone设备和Xcode,清除系统和工具缓存

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 13:52:49