swift – How do I launch my flutter app from my native iOS app code? (both flutter and native app combined)


So I’ve combined my new Flutter app and the existing native iOS app into one. The Flutter app is the new version of the same app. So in the flutter version I have a switch that can launch the user back to the older iOS native app. And on the native app there’s a switch to launch the user back to the newer Flutter version.

This is the code on the native app to switch to the flutter app.

let appDelegate = UIApplication.shared.delegate as! AppDelegate
let flutterEngine = appDelegate.flutterEngine
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
                
flutterViewController.modalPresentationStyle = .fullScreen
if let window = appDelegate.window {
    window.rootViewController = flutterViewController
    window.makeKeyAndVisible()
}

// OR the code below instead of the above if condition                   
//present(flutterViewController2, animated: true, completion: nil)

Here’s what happens, when I run the app, it launches normally in the flutter version. I click the switch and switch to the iOS version. Then from the iOS version I click the switch again and it launches the flutter version using the code above. Then when I click the switch to switch back to the native version again nothing happens.

And the log throws the following error:

flutter: MissingPluginException(No implementation found for method startNativeApp on channel nativeChannel)

startNativeApp is the method in the native iOS apps AppDelegate class which is used to switch from the Flutter version to the native version.

func presentLauncherViewController() {
    if let launcherViewController = LaunchVC.instantiateFromStoryboard() {
        launcherViewController.modalPresentationStyle = .fullScreen
        if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let window = appDelegate.window {
            window.rootViewController = launcherViewController as! UINavigationController
            window.makeKeyAndVisible()
        }
    }
}

I don’t know much of iOS. What could I be doing wrong here?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img