創(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 指令;
不報錯绣夺,成功運行起來原生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];
}