参考文档https://flutter.cn/docs/add-to-app/ios/add-flutter-screen?tab=vc-uikit-objc-tab
出于项目原因
选用该文档的B方式的 第二个方法:链接到框架
准备工作
在 Xcode 中集成 frameworks
flutter build ios-framework --output=some/path/MyApp/Flutter/(任何你想要的文件夹)
1.在项目底下创建/Flutter/Release/文件夹 从项目直接复制
项目路径/Flutter/Release/
3.然后点击以下步骤 target-> Build Phases > Link Binary With Libraries(查看包都是否都在,一般都在)。
在 target -> build settings ->Search Paths ->System Framework Search Paths (FRAMEWORK_SEARCH_PATHS) 增加
$(PROJECT_DIR)/Flutter/Release/
4.复制AppDelegate 有效内容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//创建主窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.flutterEngine = [[FlutterEngine alloc] init];
[self.flutterEngine run];
[GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];
ViewController *vc =[[ViewController alloc]init];
UINavigationController *navi =[[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController =navi;
return YES;
}
4.复制其他文件如:ViewController 等
以下是可能遇到的坑
5.xcode15版本
如果报错 [ +1 ms] Flutter failed to read a file at /user/....../.last_build_id
设置 target -> build settings -> 搜索user 把User Script Sanboxing 改为NO
6.如果 pod不支持高版本可改xcode 14版本
网友评论