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:
@@ -1,3 +1,3 @@
|
||||
PODFILE CHECKSUM: 665d7a704fb3ad8037fd80d414eb5db11ba3fc93
|
||||
PODFILE CHECKSUM: 638dc8f58cade4b6f922e82e3c1008f507581efd
|
||||
|
||||
COCOAPODS: 1.2.0
|
||||
|
||||
2
examples/flutter_view/ios/Pods/Manifest.lock
generated
2
examples/flutter_view/ios/Pods/Manifest.lock
generated
@@ -1,3 +1,3 @@
|
||||
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"]) {
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user