在Flutter中打开本机UIViewController [英] Open native UIViewController in Flutter

查看:687
本文介绍了在Flutter中打开本机UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Flutter开发的应用程序,并且有一个UIViewController必须在本机IOS中实现(没有其他解决方法,这是必须的)

I have an application I develop in Flutter, and it has one UIViewController that has to be implemented in native IOS (there is no other workaround, it is a must)

我已经实现了它,它可以根据第一个测试进行工作,但是根据您的观点,我想再次检查它是否可以正常运行,因为我对Flutter的经验还不多,所以恐怕有点弄乱我的应用程序导航堆栈中的内容,将来可能会导致错误.

I have implemented it, it works according to the first tests, but I'd like to double check if it is okkey by your opinion, as I am not so experienced in Flutter, and I am afraid a bit a make some mess in my app navigation stack that can cause bugs in the future.

因此,我已经通过MethodChannel实现了它.我有一种方法,从颤振侧"调用.我不在这里粘贴与MethodChannel相关的内容,因为它们很简单.

So, I have implemented it by MethodChannel. I have a method, that called from 'Flutter side'. I don't paste my MethodChannel related things here, as they are trivial.

在我的AppDelegate didFinishLaunchingWithOptions中,我添加了以下内容:

In my AppDelegate didFinishLaunchingWithOptions I added this:

let flutterViewController = FlutterViewController()
    self.navigationController = UINavigationController(rootViewController: flutterViewController)
    self.navigationController?.isNavigationBarHidden = true

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

我的打开方法是这样的:

And my open method like this:

private func openNativeUI(result: FlutterResult) {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let uiController = sb.instantiateViewController(withIdentifier: "nativeui")

        self.navigationController?.pushViewController(uiController, animated: true)

        result(true)
    }

您怎么看?

任何建议都将受到高度赞赏,并感谢您的提前帮助!

Any advise is highly appreciated and thank you for your help in advance!

推荐答案

在创建跨平台应用程序时使用Native API完全可以,但是请确保没有其他方法可以实现您的目标.很多时候(当跨平台引擎/SDK是新的时),除了使用本机代码来完成功能之外,您别无选择.

It's completely fine to use Native API's while creating a cross platform application but make sure there is no other way to achieve your goal. Many a times(when a cross platform engine/sdk is new) you have no choice other than using the native code to complete your functionality.

不确定您的目标,但是跨平台引擎/sdk(例如,Flutter)的常见问题是第三方SDK/API(例如,Chartboost, Stripe, Twilio)需要一些时间才能转换为该引擎/sdk您正在使用它,因此当它不可用时,您别无选择,只能以本地方式调用这些API.

Not sure about your goal but the common issue with cross platform engine/sdk's(e.g, Flutter) is that the third party SDK/API's(e.g, Chartboost, Stripe, Twilio) takes some time to translate into that engine/sdk you are using so while its not available you have no choice except to call those API's natively.

发生其他问题的原因是某些特定于平台的API,例如Camera,Contacts,In-App,GameCenter等未随跨平台SDK一起提供,或者花费一些时间来获取此类API的包装,因此在所有此类情况下,您都可以使用本机API.

Other issue happens is some platform specific API's e.g, Camera, Contacts, In-App, GameCenter etc do not come along with the cross platform SDK or it takes time to get some wrapper for such API's so in all such cases you can use Native API's.

这篇关于在Flutter中打开本机UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆