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

2023-05-08  本文已影响0人  哇哇卡

创建了flutter 工程,命名为test_flutter_Module,选择的Module;

iOS原生工程命名为:test_ios,将test_flutter_Module和test_ios 放在相同目录,是同级关系,打开原生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内容参考:

# 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所在目录,执行 pod install 指令;

不报错,成功运行起来原生iOS工程说明配置成功了,就可以在原生iOS工程中引用调用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];

}

上一篇 下一篇

猜你喜欢

热点阅读