错误:尝试呈现已经呈现的 MFMailComposeViewController

问题描述 投票:0回答:1

我尝试通过本教程向我的 Flutter iOS 应用程序添加本机启动画面:

https://medium.com/@obenkucuk/flutter-native-splash-animation-with-lottie-on-ios-3c8660b41dde

我添加到AppDelegate:

 // Runs the default Dart entrypoint with a default Flutter route.
    flutterEngine.run()
      
    // Used to connect plugins (only if you have plugins with iOS platform code).
    GeneratedPluginRegistrant.register(with: self.flutterEngine)

我的 SplashViewController 看起来像:

import UIKit
import Lottie
import Flutter

public class SplashViewController: UIViewController {
    
    private var animationView: LottieAnimationView?
    
    public override func viewDidAppear(_ animated: Bool) {
        animationView = .init(name: "splash")
        animationView!.frame = view.bounds
        animationView!.contentMode = .scaleAspectFill
        animationView!.loopMode = .playOnce
        animationView!.animationSpeed = 1.00
        view.addSubview(animationView!)
        animationView!.play{ (finished) in
            self.startFlutterApp()
        }
    }
    
    func startFlutterApp() {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        let flutterEngine = appDelegate.flutterEngine
        let flutterViewController =
            FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
        
        flutterViewController.modalPresentationStyle = .custom
        flutterViewController.modalTransitionStyle = .crossDissolve
        
        present(flutterViewController, animated: true, completion: nil)
        
    }
}

它正在工作,但如果我尝试发送带有包裹的邮件,我会遇到一个问题

flutter_email_sender
。这个错误好像是
MFMailComposeViewController
的问题:

Attempt to present <MFMailComposeViewController: 0x1508ed800> on <Runner.SplashViewController: 0x147f131c0> (from <Runner.SplashViewController: 0x147f131c0>) which is already presenting <FlutterViewController: 0x14a25f800>.

这个解决方案对我没有帮助: https://stackoverflow.com/a/59336348/3037763

如何修改我的控制器以与 MFMailComposeViewController 一起使用?

swift flutter mfmailcomposeviewcontroller
1个回答
0
投票

这意味着如果已经出现了一个 ViewController,则不允许您再出现另一个 ViewController。您可以尝试这种方法,将根窗口控制器替换为您的主

FlutterViewController

func startFlutterApp() {
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let flutterEngine = appDelegate.flutterEngine
    let flutterViewController =
        FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
    
    appDelegate.window?.rootViewController = flutterViewController //<- here
}
© www.soinside.com 2019 - 2024. All rights reserved.