為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-11 文章編輯:小燈 瀏覽次數(shù):3875
1. 新建一個(gè)xcode工程:FlutterNativeFrame
跟flutter在同級(jí)別路徑
2. binding flutter
// flutter_application_path:flutter工程的絕對(duì)路徑 flutter_application_path = '**/**/my_flutter' eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
3.執(zhí)行pod install
執(zhí)行完之后,打開(kāi)xcode工程,出現(xiàn)如圖所示的兩個(gè)文件夾,success
4. 添加腳本文件
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
ok,run,如果運(yùn)行報(bào)錯(cuò),把Enable Bitcode
設(shè)為NO
,F(xiàn)lutter混合開(kāi)發(fā)還不支持bit code,所以在iOS工程檢查項(xiàng)目并關(guān)閉bit code
現(xiàn)在應(yīng)該可以運(yùn)行起來(lái)了,如果還是不行,重復(fù)以上步驟
混編開(kāi)始:
修改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跳轉(zhuǎn)
#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工程路徑,執(zhí)行flutter attach
attach成功之后,運(yùn)行xcode,更新直接press 'r'
在VStudio中修改dart文件,press 'r'直接可以看到修改之后的顯示
官網(wǎng)鏈接:Hot reload https://flutter.io/docs/development/tools/hot-reload