Reputation: 660
I try to add a native Splash Screen to my Flutter iOS App with this tutorial:
https://medium.com/@obenkucuk/flutter-native-splash-animation-with-lottie-on-ios-3c8660b41dde
I added to 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)
and my SplashViewController looks like:
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)
}
}
It is working but I have one Problem if I try to send a mail with the package flutter_email_sender
. This error seems to be a problem with MFMailComposeViewController
:
Attempt to present <MFMailComposeViewController: 0x1508ed800> on <Runner.SplashViewController: 0x147f131c0> (from <Runner.SplashViewController: 0x147f131c0>) which is already presenting <FlutterViewController: 0x14a25f800>.
This solution is not helping me: https://stackoverflow.com/a/59336348/3037763
How could I modify my controller to work with MFMailComposeViewController as well?
Upvotes: -1
Views: 81
Reputation: 9201
This means you're not allowed to present another ViewController if one has already been presented. You can try this approach to replace the root window controller with your main 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
if let window = appDelegate.window {
UIView.transition(with: window, duration: 0.3, options: .transitionCrossDissolve, animations: nil)
}
}
Upvotes: -1