File size: 1,737 Bytes
b91a53d | 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | // Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Foundation/Foundation.h>
#import "MainViewController.h"
#import "NativeViewController.h"
@interface MainViewController ()
@property (nonatomic) NativeViewController* nativeViewController;
@property (nonatomic) FlutterViewController* flutterViewController;
@property (nonatomic) FlutterBasicMessageChannel* 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 = [FlutterBasicMessageChannel messageChannelWithName:channel
binaryMessenger:self.flutterViewController
codec:[FlutterStringCodec sharedInstance]];
MainViewController* __weak weakSelf = self;
[self.messageChannel setMessageHandler:^(id message, FlutterReply reply) {
[weakSelf.nativeViewController didReceiveIncrement];
reply(emptyString);
}];
}
}
- (void)didTapIncrementButton {
[self.messageChannel sendMessage:ping];
}
@end
|