美文网首页Flutter
iOS已有项目集成Flutter

iOS已有项目集成Flutter

作者: 我_想_静_静 | 来源:发表于2020-09-24 11:14 被阅读0次

    1.创建一个目录,把已有的安卓项目复制到里面

    2.用命令行,cd进来这个目录,flutter create --template module my_flutter,就会创建一个my_flutter的工程

    如下图所示

    3.如果iOS项目里面没用cocoapod那么新建一个Podfile文件

    4.Podfile文件里面的内容大致如下

    source 'https://github.com/CocoaPods/Specs.git'

    platform :ios, '9.0'

    target 'QiMing' do

      use_frameworks!

    #flutter_application_path = '../my_flutter'

    #eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

    flutter_application_path = '../my_flutter'

    load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

    install_all_flutter_pods(flutter_application_path)

    end

    5.如果iOS项目之前就是cocoapod项目,直接复制代码进去就行,如下

    复制进去的代码如下
    #flutter_application_path = '../my_flutter'

    #eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

    flutter_application_path = '../my_flutter'

    load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

    install_all_flutter_pods(flutter_application_path)

    6.cd进去iOS工程,pod install

    等待完成.....

    完成会如下图所示

    7.AppDelegate.h配置

    #import

    #import

    @interface AppDelegate : FlutterAppDelegate <UIApplicationDelegate>

    //@property (strong, nonatomic) UIWindow *window;

    @property (nonatomic,strong) FlutterEngine *flutterEngine;

    @end

    8.AppDelegate.m配置

    #import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h>

    - (BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

        self.flutterEngine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil];

        [self.flutterEngine runWithEntrypoint:nil];

        [GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];

        return YES;

    }

    //提示,如果不配置AppDelegate的代码,那么ios页面push flutter页面会有延迟,延迟中会出现app过渡页,体验不好

    9.页面跳转

    //    //设置路由参数

        //    [flutterViewController setInitialRoute:@"route"];

    FlutterEngine *flutterEngine = [(AppDelegate *)[[UIApplication sharedApplication] delegate] flutterEngine];

        FlutterViewController *flutterViewController = [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];

        flutterViewController.title=@"flutterTitle";

        [selfpushVC:flutterViewControlleranimated:NO];

    相关文章

      网友评论

        本文标题:iOS已有项目集成Flutter

        本文链接:https://www.haomeiwen.com/subject/jgdzyktx.html