当前位置:   article > 正文

iOS利用cocopod接入Flutter_eval(file.read(file.join(flutter_application_path,

eval(file.read(file.join(flutter_application_path, '.', '.', 'podhelper_ios.

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

2.在iOS工程中输入命令

$ flutter create -t module android_flutter_module

 

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

3.修改Podfile文件

  1. # Uncomment the next line to define a global platform for your project
  2. platform :ios, '8.0'
  3. target 'FOne' do
  4. # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  5. # use_frameworks!
  6. target 'FOneTests' do
  7. inherit! :search_paths
  8. # Pods for testing
  9. end
  10. target 'FOneUITests' do
  11. inherit! :search_paths
  12. # Pods for testing
  13. end
  14. end
  15. flutter_application_path = '../android_flutter_module'
  16. 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   

  1. "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
  2. "$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中创建一个按钮点击

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

哒哒哒。。。。。。 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/145283
推荐阅读
相关标签
  

闽ICP备14008679号