iOS利用cocopod接入Flutter

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

2.在iOS工程中输入命令

$ flutter create -t module android_flutter_module

 iOS利用cocopod接入Flutter_第1张图片

该命令将会创建一个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

iOS利用cocopod接入Flutter_第2张图片

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

5.pod install

iOS利用cocopod接入Flutter_第3张图片

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

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

iOS利用cocopod接入Flutter_第4张图片

iOS利用cocopod接入Flutter_第5张图片

7.测试

在ViewController中创建一个按钮点击

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

哒哒哒。。。。。。 

iOS利用cocopod接入Flutter_第6张图片

你可能感兴趣的:(Flutter)