Flutter三端分離在iOS中配置flutter信息

創(chuàng)建了flutter 工程,命名為test_flutter_Module,選擇的Module;

iOS原生工程命名為:test_ios,將test_flutter_Module和test_ios 放在相同目錄,是同級關(guān)系,打開原生iOS工程test_ios 的podfile文件:

添加幾行代碼:

#1、添加新flutter版本需要

?? flutter_post_install(installer) if defined?(flutter_post_install)

#2、 Flutter模塊加入

flutter_application_path = '../test_flutter_Module/'

load File.join(flutter_application_path,'.ios','Flutter','podhelper.rb')

#3、安裝嵌入Flutter模塊

? install_all_flutter_pods(flutter_application_path)

貼上添加podfile內(nèi)容參考:

# Uncomment the next line to define a global platform for your project

# platform :ios, '11.0'

post_install do |installer|

? #1、添加新flutter版本需要

? flutter_post_install(installer) if defined?(flutter_post_install)

? installer.pods_project.targets.each do |target|

? ? target.build_configurations.each do |config|

? ? ? config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'

? ? end

? end

end

# 2、Flutter模塊加入

flutter_application_path = '../test_flutter_Module/'

load File.join(flutter_application_path,'.ios','Flutter','podhelper.rb')

target 'test_ios' do

? # Comment the next line if you don't want to use dynamic frameworks

? use_frameworks!

? #3、安裝嵌入Flutter模塊

? install_all_flutter_pods(flutter_application_path)

? # Pods for?test_ios

? pod 'AFNetworking', '~> 4.0'

? pod 'Masonry'

? target 'test_iosTests' do

? ? inherit! :search_paths

? ? # Pods for testing

? end

? target 'test_iosUITests' do

? ? # Pods for testing

? end

end


添加完,cd到test_ios所在目錄,執(zhí)行?pod install 指令;

不報(bào)錯,成功運(yùn)行起來原生iOS工程說明配置成功了,就可以在原生iOS工程中引用調(diào)用flutter了:

下面是測試代碼:

#import?<Flutter/Flutter.h>

-(void)viewDidLoad{[superviewDidLoad];

UIButton*button = [UIButton buttonWithType:UIButtonTypeCustom];

[button addTarget:selfaction:@selector(showFlutter)forControlEvents:UIControlEventTouchUpInside];[button setTitle:@"Show Flutter!"forState:UIControlStateNormal];

button.backgroundColor=UIColor.blueColor;

button.frame = CGRectMake(80.0,210.0,160.0,40.0);

[self.view addSubview:button];

}

-(void)showFlutter{

FlutterViewController*flutterViewController=[[FlutterViewController alloc]initWithProject:nil nibName:nil bundle:nil];

[selfpresentViewController:flutterViewController animated:YES completion:nil];

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容