第一步,将flutter项目创建在iOS项目同目录中
image.png注意:此处创建的是flutter module,不是flutter project
flutter create -t module flutter_lab
第二步,在podfile文件中加入以下脚本,然后pod install
flutter_application_path = '../flutter_lab/'
target 'Test' do
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')),binding)
end
第三步,Run Script
# 删除本地Flutter文件夹
rm -rf -- "$SOURCE_ROOT/Flutter"
# 再生成Flutter文件夹
mkdir -p "$SOURCE_ROOT/Flutter"
# 编译生成
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
# 将胶水文件copy到本地文件夹
cp -r -- "$FLUTTER_APPLICATION_PATH/.ios/Flutter/flutter_assets" "$SOURCE_ROOT/Flutter"
cp -r -- "$FLUTTER_APPLICATION_PATH/.ios/Flutter/App.framework" "$SOURCE_ROOT/Flutter"
第四步,编译iOS项目,将编译生成flutter文件导入iOS项目
目录中会生成flutter文件夹,在iOS工程目录中新建Flutter文件夹,将App.framework和flutter_assets导入到刚建立的Flutter文件夹,切记flutter_assets使用Creat folder references方式导入
image.png第五步,导入App.framework
image.png第五步,改造AppDelegate
#import <UIKit/UIKit.h>
#import <Flutter/Flutter.h>
@interface AppDelegate : FlutterAppDelegate
@end
#import "AppDelegate.h"
#import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
网友评论