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
This commit is contained in:
Sarah Zakarias
2017-03-16 09:32:19 +01:00
committed by GitHub
parent dc83c4913a
commit 6314a6c091
4 changed files with 19 additions and 14 deletions

View File

@@ -1,3 +1,3 @@
PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93
PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd
COCOAPODS: 1.2.0

View File

@@ -1,3 +1,3 @@
PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93
PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd
COCOAPODS: 1.2.0

View File

@@ -13,7 +13,6 @@
@protocol NativeViewControllerDelegate;
@interface MainViewController : UIViewController <FlutterMessageListener,
NativeViewControllerDelegate>
@interface MainViewController : UIViewController <NativeViewControllerDelegate>
@end

View File

@@ -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