為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-11 文章編輯:小燈 瀏覽次數(shù):4050
1. 新建一個(gè)xcode工程:FlutterNativeFrame
跟flutter在同級(jí)別路徑
image.png 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)
image.png3.執(zhí)行pod install
執(zhí)行完之后,打開xcode工程,出現(xiàn)如圖所示的兩個(gè)文件夾,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,如果運(yùn)行報(bào)錯(cuò),把Enable Bitcode 設(shè)為NO,F(xiàn)lutter混合開發(fā)還不支持bit code,所以在iOS工程檢查項(xiàng)目并關(guān)閉bit code
image.png 現(xiàn)在應(yīng)該可以運(yùn)行起來了,如果還是不行,重復(fù)以上步驟
混編開始:
修改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'
image.png 在VStudio中修改dart文件,press 'r'直接可以看到修改之后的顯示
官網(wǎng)鏈接:Hot reload https://flutter.io/docs/development/tools/hot-reload