zoukankan      html  css  js  c++  java
  • OC端代码

    ViewController.m

    #import "ViewController.h"
    #import <Flutter/Flutter.h>
    #include "GeneratedPluginRegistrant.h"
    #import "SettingViewController.h"

    @interface ViewController ()
    {
    FlutterViewController *flutterVC;
    FlutterMethodChannel *batteryChannel;
    }
    @end

    @implementation ViewController


    - (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.title = @"我是iOS 页面";

    flutterVC = [[FlutterViewController alloc]initWithProject:nil nibName:nil bundle:nil];
    flutterVC.title = @"我是Flutter页面";
    batteryChannel = [FlutterMethodChannel methodChannelWithName:@"samples.flutter.dev/battery" binaryMessenger:flutterVC];
    }


    - (IBAction)pushNext:(id)sender {
    NSLog(@"你好吗?");

    //如果使用了插件显示view
    [GeneratedPluginRegistrant registerWithRegistry:flutterVC];
    //[flutterVC setInitialRoute:@"myApp12"];
    [flutterVC setInitialRoute:@"myApp"];
    [self.navigationController pushViewController:flutterVC animated:YES];

    __weak typeof(self) weakSelf = self;
    [batteryChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
    // Note: this method is invoked on the UI thread.
    if ([@"getBatteryLevel" isEqualToString:call.method])
    {
    int batteryLevel = [weakSelf getBatteryLevel];
    if (batteryLevel == -1) {
    result([FlutterError errorWithCode:@"UNAVAILABLE" message:@"Battery info unavailable" details:nil]);
    } else {(http://www.amjmh.com)
    result(@(batteryLevel));
    }

    } else if ([@"backToNavigatorIndex" isEqualToString:call.method]) {
    NSArray *arguments = call.arguments;

    NSNumber *inde = arguments[0];
    NSLog(@"arguments :%@",inde);
    int batteryLevel = [weakSelf backToNavigatorIndex:inde];
    result(@(batteryLevel));
    } else {
    result(FlutterMethodNotImplemented);
    }
    }];
    }


    - (IBAction)passArgusToFlutter:(id)sender {

    NSLog(@"passArgusToFlutter");
    [batteryChannel invokeMethod:@"passArgusToFlutter" arguments:@[@12,@"huahua"] result:^(id _Nullable result) {
    NSString *ggg = (NSString *)result;
    NSLog(@"result----:%@",ggg);
    }];
    }


    - (int)getBatteryLevel {
    NSLog(@"nihao!!!!!");
    SettingViewController *settingVC = [[SettingViewController alloc]init];
    [flutterVC.navigationController pushViewController:settingVC animated:YES];

    return 66;
    }


    - (int)backToNavigatorIndex:(NSNumber*)index {
    NSLog(@"backToNavigatorIndex!!!!!");
    UIViewController *VC = flutterVC.navigationController.viewControllers[0];
    [flutterVC.navigationController popToViewController:VC animated:YES];

    return 33;
    }

    ---------------------

  • 相关阅读:
    极简风格网络消息以及分发架构
    GPS网络时间服务器是如何让集成系统协调工作的?
    北斗授时设备(NTP时间服务器)对高速联网收费的重要性
    卫星互联网路由技术现状及展望
    【Python】获取中国法定节假日的封装
    GCC 内联汇编基础
    MIT6.828——Lab1 partB(麻省理工操作系统课程实验)
    MIT6.828——Lab1 partA(麻省理工操作系统课程实验)
    bochs(2.6.11)配置安装
    MIT6.828(Step0)——实验环境配置
  • 原文地址:https://www.cnblogs.com/ly570/p/11295921.html
Copyright © 2011-2022 走看看