> For the complete documentation index, see [llms.txt](https://devbook.site/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devbook.site/3-jiao-hu/jiao-hu-shi-ios-duan-de-dai-ma-bian-xie.md).

# 第2节：交互时iOS端的代码编写

本节学习内容：原生iOS项目在交互时的代码编写。

本节学习用时：**30分钟**

本节学习方式：动手实践

本节目录：

一、本节内容介绍

二、本节代码解释

## 一、本节内容介绍

略！

## 二、本节代码解释

### 1、本节代码

```
- (void)showMainFlutterViewControllerWithoutParam {
    self.navigationController.navigationBarHidden = YES;

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

    NSString *channelName = @"com.dvlproad.ciyouzen/platform_channel";// 要与.dart中一致
    FlutterMethodChannel *messageChannel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:flutterViewController];

    [messageChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
        // call.method获取flutter给回到的方法名,要匹配到channelName对应的多个 发送方法名,一般需要判断区分
        // call.arguments获取到flutter给到的参数,(比如跳转到另一个页面所需要参数)
        // result是给flutter的回调,只能回调一次
        NSString *message = [NSString stringWithFormat:@"flutter回调:\n nmethod = %@\n arguments = %@", call.method, call.arguments];
        NSLog(@"%@", message);

        if ([call.method isEqualToString:@"showToast"]) {
            [CJToast shortShowMessage:message];
            return;

        } else if ([call.method isEqualToString:@"goBack"]) {
            [self.navigationController popViewControllerAnimated:YES];
            return;

        } else if ([call.method isEqualToString:@"goiosPage"]) {
            OCCallFlutterViewController *viewController = [[OCCallFlutterViewController alloc] init];
            viewController.parames = call.arguments;
            [self.navigationController pushViewController:viewController animated:YES];
            return;

        } else if ([call.method isEqualToString:@"changeLeftBarButtonAction"]) {
            NSDictionary *params = @{@"imageName":@"lib/Resources/message_arrow.png"};
            result(params);
            return;
        }

        result(FlutterMethodNotImplemented);
    }];

    [self.navigationController pushViewController:flutterViewController animated:YES];
}
```
