How to change the root view controller back to flutter from native iOS?

烈酒焚心 提交于 2020-01-14 04:06:52

问题


I'm building an application where I use platform channel of flutter to navigate to iOS native. There I change the rootViewController of the app to a native TabViewController. When the user clicks back I want to navigate back to flutter but the app freezes. Is there a safe way to do this?

I have tried saving the state of the flutterViewController before change and handing it back when the user presses back.

this code is for the flutter side to navigate to the native iOS view.

                 var result = await AppConstant.channel_iOS.invokeMethod(AppConstant.method_open_sermon_player);
                 if(result != null && result[AppConstant.key_restart_ui])
                 {
                   RestartWidget.restartApp(context);
                 }
                 print(result);

                }

this is for the native iOS side to receive the control of the app from flutter.

let flutterChannel = FlutterMethodChannel.init(name: "iOS", binaryMessenger: flutterViewController);

    flutterChannel.setMethodCallHandler { (flutterMethodCall, flutterResult) in

        if flutterMethodCall.method == "openSermonPlayer" {

            UIView.animate(withDuration: 0.5, animations: {
                self.window?.rootViewController = nil

                let viewToPush = PlayerTabViewController()


                    self.window = UIWindow(frame: UIScreen.main.bounds)
                    self.window?.makeKeyAndVisible()
                    self.window.rootViewController = viewToPush



            })

            if CheckIfPlaying.sharedInstance.quitSermon == true {
                CheckIfPlaying.sharedInstance.quitSermon = false
                let result = ["restart_ui": self.switchBack()]
                flutterResult(result)
            }
        }

I expect the app to change its rootViewController to flutter and keep on working but it just freezes on that view.

来源:https://stackoverflow.com/questions/57889520/how-to-change-the-root-view-controller-back-to-flutter-from-native-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!