iOS利用cocopod接入Flutter

1.创建一个新的iOS工程,并添加cocopod

2.在iOS工程中输入命令

$ flutter create -t module android_flutter_module

 

该命令将会创建一个module类型的flutter工程

3.修改Podfile文件

# Uncomment the next line to define a global platform for your project
platform :ios, '8.0'

target 'FOne' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
target 'FOneTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'FOneUITests' do
    inherit! :search_paths
    # Pods for testing
  end


end
flutter_application_path = '../android_flutter_module'
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

只需要添加

flutter_application_path = '../android_flutter_module'
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

这两行就行了,这里应该注意flutter_application_path路径是第二步创建的module绝对路径,因为在Podfile文件的上层文件夹,这里只需要‘’ ../ ‘’就行,也推荐把module创建在上层文件夹中

4.修改Xocde配置

   4.1   修改Xocde Build Setting中Enable Bitcode为NO

   4.2   添加Run Script   

"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed

注意:如果是Xcode10以上版本需要删除 project.pbxproj文件中的inputFileListPathsoutputFileListPaths

5.pod install

出现Development Pods文件夹就可以进行下一步(该文件夹下不一定有这么多子文件夹)

6.修改iOS工程中的AppDelegate.h文件和AppDelegate.m文件

7.测试

在ViewController中创建一个按钮点击

- (void)handleButtonAction {
    FlutterViewController *flutterViewController = [[FlutterViewController alloc] init];
    flutterViewController.view.backgroundColor = [UIColor cyanColor];
    [flutterViewController setInitialRoute:@"route1"];
    [self presentViewController:flutterViewController animated:YES completion:nil];
}

哒哒哒。。。。。。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值