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 COCOAPODS: 1.2.0
PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93 PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd
COCOAPODS: 1.2.0 COCOAPODS: 1.2.0
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
@protocol NativeViewControllerDelegate; @protocol NativeViewControllerDelegate;
@interface MainViewController : UIViewController <FlutterMessageListener, @interface MainViewController : UIViewController <NativeViewControllerDelegate>
NativeViewControllerDelegate>
@end @end
...@@ -10,11 +10,13 @@ ...@@ -10,11 +10,13 @@
@interface MainViewController () @interface MainViewController ()
@property (strong, nonatomic) NativeViewController* nativeViewController; @property (nonatomic) NativeViewController* nativeViewController;
@property (strong, nonatomic) FlutterViewController* flutterViewController; @property (nonatomic) FlutterViewController* flutterViewController;
@property (nonatomic) FlutterMessageChannel* messageChannel;
@end @end
static NSString* const emptyString = @""; static NSString* const emptyString = @"";
static NSString* const ping = @"ping";
static NSString* const channel = @"increment"; static NSString* const channel = @"increment";
@implementation MainViewController @implementation MainViewController
...@@ -23,11 +25,6 @@ static NSString* const channel = @"increment"; ...@@ -23,11 +25,6 @@ static NSString* const channel = @"increment";
return channel; return channel;
} }
- (NSString*)didReceiveString:(NSString*)message {
[self.nativeViewController didReceiveIncrement];
return emptyString;
}
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender { - (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender {
if ([segue.identifier isEqualToString: @"NativeViewControllerSegue"]) { if ([segue.identifier isEqualToString: @"NativeViewControllerSegue"]) {
...@@ -36,13 +33,22 @@ static NSString* const channel = @"increment"; ...@@ -36,13 +33,22 @@ static NSString* const channel = @"increment";
} }
if ([segue.identifier isEqualToString:@"FlutterViewControllerSegue"]) { if ([segue.identifier isEqualToString:@"FlutterViewControllerSegue"]) {
self.flutterViewController = segue.destinationViewController; 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 { - (void)didTapIncrementButton {
[self.flutterViewController sendString:emptyString withMessageName:self.messageName]; [self.messageChannel sendMessage:ping replyHandler:nil];
} }
@end @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