1、Flutter环境配置 Flutter中文网 跟着里面一步一步来就完事了。
2、iOS工程Enable Bitcode 需要关闭,因为Flutter混合开发目前还不支持Bitcode
3、创建flutter module
FlutterMixDemo/BaseFramework/ (BaseFramework 是我的 iOS 工程项目)
进入在 FlutterMixDemo 目录下,终端执行命令:
flutter create -t module flutter_module
flutter_module是自己起的名字,记得字母都要小写,不然会报错。
这里也有Flutter官方网站英文文档 → iOS接入Flutter教程
4、添加以下代码到Podfile:(没有Podfile怎么办?终端先cd到BaseFramework项目里,执行pod init)
platform :ios, '9.0'
target 'BaseFramework' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
#需要添加的代码 flutter_module是自己创建的名字
flutter_application_path = '../flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
install_all_flutter_pods(flutter_application_path)
end
执行pod install,如果有报错,根据错误提示一个个解决,具体哪些报错不懂的话就谷歌百度吧。。。
注意:当你在flutter_module/pubspec.yaml中有改变了Flutter插件的依赖关系时(不管有没修改啥,只要按了command+s保存后),一定要在BaseFramework(自己的项目)里再次运行pod install。
5、在iOS应用里使用 FlutterViewController
创建FlutterEngine
AppDelegate.h
@import UIKit;
@import Flutter;
@interface AppDelegate : FlutterAppDelegate
@property (nonatomic,strong) FlutterEngine *flutterEngine;
@end
AppDelegate.m
#import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h> // Used to connect plugins.
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
self.flutterEngine = [[FlutterEngine alloc] initWithName:@"my flutter engine"];
// Runs the default D