Commit 6314a6c0 authored by Sarah Zakarias's avatar Sarah Zakarias Committed by GitHub

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
parent dc83c491
PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93
PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd
COCOAPODS: 1.2.0
PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93
PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd
COCOAPODS: 1.2.0
......@@ -13,7 +13,6 @@
@protocol NativeViewControllerDelegate;
@interface MainViewController : UIViewController <FlutterMessageListener,
NativeViewControllerDelegate>
@interface MainViewController : UIViewController <NativeViewControllerDelegate>
@end
......@@ -10,11 +10,13 @@
@interface MainViewController ()
@property (strong, nonatomic) NativeViewController* nativeViewController;
@property (strong, nonatomic) FlutterViewController* flutterViewController;
@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
......@@ -23,11 +25,6 @@ static NSString* const channel = @"increment";
return channel;
}
- (NSString*)didReceiveString:(NSString*)message {
[self.nativeViewController didReceiveIncrement];
return emptyString;
}
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender {
if ([segue.identifier isEqualToString: @"NativeViewControllerSegue"]) {
......@@ -37,12 +34,21 @@ static NSString* const channel = @"increment";
if ([segue.identifier isEqualToString:@"FlutterViewControllerSegue"]) {
self.flutterViewController = segue.destinationViewController;
[self.flutterViewController addMessageListener:self];
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.flutterViewController sendString:emptyString withMessageName:self.messageName];
[self.messageChannel sendMessage:ping replyHandler:nil];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment