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

Flutter iOS原生启动屏集成后MFMailComposeViewController弹窗异常求助

问题解决方法

报错原因是SplashViewController通过present方式展示FlutterViewController后,自身始终处于"正在呈现控制器"的状态,后续flutter_email_sender插件尝试在它上面弹出邮件控制器时,就会触发"已在呈现另一个控制器"的冲突。

修改SplashViewController中的startFlutterApp方法,将FlutterViewController设置为应用的根控制器,替代原有的present方式:

func startFlutterApp() {
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let flutterEngine = appDelegate.flutterEngine
    let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
    
    // 兼容iOS 13+的窗口设置
    if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
       let window = scene.windows.first {
        window.rootViewController = flutterViewController
        window.makeKeyAndVisible()
    } else {
        // 兼容iOS 12及以下版本
        UIApplication.shared.keyWindow?.rootViewController = flutterViewController
    }
}

这样修改后,SplashViewController会被完全替换掉,FlutterViewController成为应用的根控制器,后续所有弹出控制器(包括邮件控制器)的操作都会在正确的上下文执行,不会再出现冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 23:32:06