老工程集成flutter有两大方法:ios
综合考虑后使用第二种方法更加适合咱们,具体流程以下web
老工程导入flutter相关文件
a. 首先编译纯flutter工程A(命令行flutter build ios –release)
b. 把A工程ios/Flutter文件夹复制到老的非Flutter B工程
c. B工程把复制过来的Flutter目录做为group添加进工程(先新建一个Flutter group,而后把sdk包里的Flutter目录复制到工程的Flutter,而后再在工程中添加文件, Flutter是黄色的, flutter_assets是绿色的, build->phases->copy bundle resource下自动添加flutter_assets目录,而不是里面的文件)
d.复制A工程中的GeneratedPluginRegistrant.h/mm到B工程,一样添加进工程xcode
添加framework, general->linked Frameworks: 添加app.framework和flutter.frameworkruby
添加打包资源
a.Build Phases->Copy Bundle Resources下添加flutter_assets,这个目录保护全部的flutter脚本和资源
b.Build Phases下点”+”建立一个New Copy Files Phase,Destination选择Frameworks, name下添加app.framework和flutter.framework, 这步不成功提示找不到flutter image架构
移植flutter pod,flutter的插件通常在ios下是个xcode工程,因此须要在podfile中引入本地的这个插件工程:
第一步:在flutter下安装这个插件,使得插件xcode下载到本地 通常在flutter/.pub-cache/hosted/pub.dartlang.org/下
第二步:编辑Podfile文件引入这个本地的xcode插件,相似app
pod 'shared_preferences', :path => '/Users/zt-2012498/Desktop/data/software/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.2/ios'
工程的architectures须要改为arm64,由于cocospod上的IJKMediaFramework不支持某些架构指令集svg
关闭Bitcode, build Settings->enable Bitcode Yes改成no函数
修改B工程代码
a.建立一个ViewControllor视图,基类为FlutterViewController,默认的空类便可,这个view将用于后面给flutter渲染, flutter内的界面切来切去对于原生而言都是在这个view内显示的画面而已
a.修改AppDelegate.h 把appDelegate的基类改为FlutterAppDelegate
b.修改AppDelegate.m 在didFinishLaunchingWithOptions函数内添加ui
self.window.rootViewController = view;
//执行registerWithRegistry时window.rootViewController必须是flutterViewController的子类,不然插件通讯受印象
//参考[图片]FlutterAppDeleate.mm binaryMessager函数
[GeneratedPluginRegistrant registerWithRegistry:self];
self.window.rootViewController = nc; //执行registerWithRegistry后就能够改为本身须要的rootView了
[self.window makeKeyAndVisible];
return [super application:application didFinishLaunchingWithOptions:launchOptions];