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;
}

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

posted on 2019-08-03 19:15  激流勇进1  阅读(321)  评论(0编辑  收藏  举报