Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么实现原生主动给 flutter 发消息 #38

Closed
OHeroJ opened this issue Mar 19, 2019 · 4 comments
Closed

怎么实现原生主动给 flutter 发消息 #38

OHeroJ opened this issue Mar 19, 2019 · 4 comments

Comments

@OHeroJ
Copy link

OHeroJ commented Mar 19, 2019

怎么实现原生主动给 flutter 发消息

@nightwolf-chen
Copy link
Contributor

请参考MethodChannel的实现.

@OHeroJ
Copy link
Author

OHeroJ commented Mar 21, 2019

FlutterViewController *controller = (FlutterViewController *)self.window.rootViewController;
    
    /**********原生主动传值给flutter-Start**********/
    _nativeCount = 0;
    
    NSLog(@"原生实现 原生传值给flutter的通道标识");
    FlutterEventChannel *eventChannel = [FlutterEventChannel eventChannelWithName:@"https://www.jianshu.com/p/7dbbd3b4ce32" binaryMessenger:controller];
    //设置代理
    [eventChannel setStreamHandler:self];
    
    /**********原生主动传值给flutter-End**********/

之前通信是通过 FlutterViewController, 但是现在都是 FLBFlutterViewContainer(不是FlutterBinaryMessenger的实现), 要使用eventChannel要怎么办?

@TooXu
Copy link

TooXu commented Mar 31, 2019

FlutterViewController *controller = (FlutterViewController *)self.window.rootViewController;
    
    /**********原生主动传值给flutter-Start**********/
    _nativeCount = 0;
    
    NSLog(@"原生实现 原生传值给flutter的通道标识");
    FlutterEventChannel *eventChannel = [FlutterEventChannel eventChannelWithName:@"https://www.jianshu.com/p/7dbbd3b4ce32" binaryMessenger:controller];
    //设置代理
    [eventChannel setStreamHandler:self];
    
    /**********原生主动传值给flutter-End**********/

之前通信是通过 FlutterViewController, 但是现在都是 FLBFlutterViewContainer(不是FlutterBinaryMessenger的实现), 要使用eventChannel要怎么办?
@OHeroJ
你好,请问设置 eventChannel 的问题已经解决了吗?可以贴一下相关实例吗?

@TooXu
Copy link

TooXu commented Mar 31, 2019

[FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router onStart:^(FlutterViewController *vc) {
    
    FlutterMethodChannel *someChannel = [FlutterMethodChannel methodChannelWithName:@"channelName" binaryMessenger:vc];
    [someChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
        if ([call.method isEqualToString:@"someMethod"]) {
            result(someResult);
        }else {
            result(FlutterMethodNotImplemented);
        }
    }];
}];

已解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants