flutter/examples/flutter_view/ios/Runner/MainViewController.m
Sarah Zakarias 6314a6c091 Update iOS part of flutter_view to use the new platform message channel (#8762)
* Update iOS part of flutter_view to use the new platform message channel

* remove newline

* comments
2017-03-16 09:32:19 +01:00

55 lines
1.8 KiB
Objective-C

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.Copyright © 2017 The Chromium Authors. All rights reserved.
#import <Foundation/Foundation.h>
#import "MainViewController.h"
#import "NativeViewController.h"
@interface MainViewController ()
@property (nonatomic) NativeViewController* nativeViewController;
@property (nonatomic) FlutterViewController* flutterViewController;
@property (nonatomic) FlutterMessageChannel* messageChannel;
@end
static NSString* const emptyString = @"";
static NSString* const ping = @"ping";
static NSString* const channel = @"increment";
@implementation MainViewController
- (NSString*) messageName {
return channel;
}
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender {
if ([segue.identifier isEqualToString: @"NativeViewControllerSegue"]) {
self.nativeViewController = segue.destinationViewController;
self.nativeViewController.delegate = self;
}
if ([segue.identifier isEqualToString:@"FlutterViewControllerSegue"]) {
self.flutterViewController = segue.destinationViewController;
self.messageChannel = [FlutterMessageChannel messageChannelNamed:channel
binaryMessenger:self.flutterViewController
codec:[FlutterStringCodec sharedInstance]];
MainViewController* __weak weakSelf = self;
[self.messageChannel setMessageHandler:^(id message, FlutterReplyHandler replyHandler) {
[weakSelf.nativeViewController didReceiveIncrement];
replyHandler(emptyString);
}];
}
}
- (void)didTapIncrementButton {
[self.messageChannel sendMessage:ping replyHandler:nil];
}
@end