From 6314a6c0914e370a16ae1a6f2225200819e23f74 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Thu, 16 Mar 2017 09:32:19 +0100 Subject: [PATCH] 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 --- examples/flutter_view/ios/Podfile.lock | 2 +- examples/flutter_view/ios/Pods/Manifest.lock | 2 +- .../ios/Runner/MainViewController.h | 3 +-- .../ios/Runner/MainViewController.m | 26 ++++++++++++------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/flutter_view/ios/Podfile.lock b/examples/flutter_view/ios/Podfile.lock index e59aae3535..55767e1c13 100644 --- a/examples/flutter_view/ios/Podfile.lock +++ b/examples/flutter_view/ios/Podfile.lock @@ -1,3 +1,3 @@ -PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93 +PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd COCOAPODS: 1.2.0 diff --git a/examples/flutter_view/ios/Pods/Manifest.lock b/examples/flutter_view/ios/Pods/Manifest.lock index e59aae3535..55767e1c13 100644 --- a/examples/flutter_view/ios/Pods/Manifest.lock +++ b/examples/flutter_view/ios/Pods/Manifest.lock @@ -1,3 +1,3 @@ -PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93 +PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd COCOAPODS: 1.2.0 diff --git a/examples/flutter_view/ios/Runner/MainViewController.h b/examples/flutter_view/ios/Runner/MainViewController.h index 999cd2619c..15d94bf677 100644 --- a/examples/flutter_view/ios/Runner/MainViewController.h +++ b/examples/flutter_view/ios/Runner/MainViewController.h @@ -13,7 +13,6 @@ @protocol NativeViewControllerDelegate; -@interface MainViewController : UIViewController +@interface MainViewController : UIViewController @end diff --git a/examples/flutter_view/ios/Runner/MainViewController.m b/examples/flutter_view/ios/Runner/MainViewController.m index e8774fb7f2..22819ace9e 100644 --- a/examples/flutter_view/ios/Runner/MainViewController.m +++ b/examples/flutter_view/ios/Runner/MainViewController.m @@ -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"]) { @@ -36,13 +33,22 @@ static NSString* const channel = @"increment"; } if ([segue.identifier isEqualToString:@"FlutterViewControllerSegue"]) { - self.flutterViewController = segue.destinationViewController; - [self.flutterViewController addMessageListener:self]; + 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.flutterViewController sendString:emptyString withMessageName:self.messageName]; + [self.messageChannel sendMessage:ping replyHandler:nil]; } @end