当前位置:   article > 正文

flutter 作为模块引入 iOS 项目_flutter 以so引入ios

flutter 以so引入ios

原文 http://summerxx.com/2023/01/28/ios-use-flutter/

前言: 上篇我讲了下 flutter 环境在 MacOs 下搭建, 今天写下如何在一个成熟的 iOS 项目内引用 flutter, Demo 会放到文章最后哈

上篇 : MacOS 下配置flutter 环境

大致如下:

在项目内创建一个 flutter 模块
新建一个 Podfile, 然后进行编写, 之后安装
修改 Xcode 配置, 再次安装
书写, 测试 flutter页面

创建一个 flutter 模块

flutter create --template module flutter_module
  • 1

创建一个 Podfile

platform :ios, '11.0'
flutter_application_path = 'flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'ios_flutter_demo' do
  use_frameworks!
  install_all_flutter_pods(flutter_application_path)

  pod 'AFNetworking'

end

# 新增的配置
post_install do |installer|
  flutter_post_install(installer) if defined?(flutter_post_install)
end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

安装

pod install
  • 1

错误
截屏2023-01-28 17.21.38
修改Xcode 配置
截屏2023-01-28 17.05.32
之后重新安装 pod, 就会在项目里面成功引用了 flutter 相关的包, 如下图所示
截屏2023-01-28 17.38.43

测试代码

#import "ViewController.h"
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
#import <Flutter/Flutter.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupViews];
}

- (void)setupViews
{
    UIButton *test = [UIButton buttonWithType:UIButtonTypeCustom];
    test.backgroundColor = UIColor.blueColor;
    [test setTitle:@"Test Flutter" forState:UIControlStateNormal];
    [self.view addSubview:test];

    [test mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(100);
        make.height.mas_equalTo(50);
    }];

    [[test rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"按钮被点击了");

        FlutterViewController *vc = [[FlutterViewController alloc] init];
        [self presentViewController:vc animated:YES completion:nil];
    }];
}
@end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

效果图
https://p.ipic.vip/myq7c3.png

问题 Specs satisfying the Flutter (fromflutter_module/.ios/Flutter) dependency were found, but they required a higher minimum deployment target.

解决 https://blog.csdn.net/u011519923/article/details/116785638

文章参照 :

https://blog.csdn.net/jdd92/article/details/121938342

Demo:

https://github.com/summerxx27/flutter_ios_demo

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号