发表日期:2018-11 文章编辑:小灯 浏览次数:4147
1. 新建一个xcode工程:FlutterNativeFrame
跟flutter在同级别路径
image.png 2. binding flutter
// flutter_application_path:flutter工程的绝对路径 flutter_application_path = '**/**/my_flutter' eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
image.png3.执行pod install
执行完之后,打开xcode工程,出现如图所示的两个文件夹,success
image.png 4. 添加脚本文件
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
image.png
image.pngok,run,如果运行报错,把Enable Bitcode 设为NO,Flutter混合开发还不支持bit code,所以在iOS工程检查项目并关闭bit code
image.png 现在应该可以运行起来了,如果还是不行,重复以上步骤
混编开始:
修改AppDelegate.h、AppDelegate.m
// .h #import <UIKit/UIKit.h> #import <Flutter/Flutter.h>@interface AppDelegate : FlutterAppDelegate @end// .m #import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h> // Only if you have Flutter Plugins#include "AppDelegate.h"@implementation AppDelegate// This override can be omitted if you do not have any Flutter Plugins. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; }@end ViewController跳转
#import <Flutter/Flutter.h> #import "ViewController.h"@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:selfaction:@selector(handleButtonAction)forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Press me" forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor blueColor]]; button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); [self.view addSubview:button]; }- (void)handleButtonAction { FlutterViewController* flutterViewController = [[FlutterViewController alloc] init]; [self presentViewController:flutterViewController animated:false completion:nil]; } @end cd到flutter工程路径,执行flutter attach
attach成功之后,运行xcode,更新直接press 'r'
image.png 在VStudio中修改dart文件,press 'r'直接可以看到修改之后的显示
官网链接:Hot reload https://flutter.io/docs/development/tools/hot-reload