iOS与native交互返回值问题
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner forName:(NSString *)name;
- (void)sendEvent:(NSString *)eventName arguments:(NSDictionary *)arguments; 目前这两个方法能力有限,可以满足flutter native互相调用,但调用后再有result返回值的时候无法处理,我看iOS native端是有实现这些方法的,但是被privite,能否公开出来?
您说的private的方法是哪个?可否具体点?
把源码读了一遍没有找到从native返回结果的实现。android端可以在Router的实现中使用startActivityForResult来传递结果,只要按boost指定的key设置值就行。ios端似乎是不用像android那样利用intent传值的,但是,要适配boost还是有几个环节要处理的。
我参照了FLBFlutterViewContainer的实现,可以在现有的native页面返回。
#import "UIViewControllerDemo.h"
#import <Flutter/Flutter.h>
#import <flutter_boost/FlutterBoostPlugin.h>
#import <flutter_boost/BoostMessageChannel.h>
@interface UIViewControllerDemo ()
@property (nonatomic,copy,readwrite) NSString *name;
@property (nonatomic,strong,readwrite) NSDictionary *params;
@property (nonatomic,assign) long long identifier;
@end
@implementation UIViewControllerDemo
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)setName:(NSString *)name params:(NSDictionary *)params
{
// 这里参照FLBFlutterViewContainer中的实现,didInitPageContainer调用很关键
if(!_name && name){
_name = name;
_params = params;
NSLog(@"call me when page finished, and your result is:%@", _params);
[BoostMessageChannel didInitPageContainer:^(NSNumber *r) {}
pageName:name
params:params
uniqueId:@"abc"];
}
}
- (IBAction)pushFlutterPage:(id)sender {
[FlutterBoostPlugin open:@"first" urlParams:@{kPageCallBackId:@"MycallbackId#1"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary *result) {
NSLog(@"call me when page finished, and your result is:%@", result);
} completion:^(BOOL f) {
NSLog(@"page is opened");
}];
}
- (IBAction)present:(id)sender {
// 返回结果
[FlutterBoostPlugin close:@"abc" result:@{@"a":@(1)} exts:@{} completion:^(BOOL f) {
NSLog(@"page is complete");
}];
}
//- (NSString *)uniqueIDString
//{
// return @(_identifier).stringValue;
//}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
ios不会,根据项目中的demo改的。
另外,BoostMessageChannel.h不是public的,我自行添加到public了。
期待正确的实现方法。@noborder
我理解这几个方法都是flutter_boost内部私有方法来负责页面跳转使用的,flutter_boost只负责页面栈的管理。至于flutter与native的其他交互可以创建及使用自己的methodChannel @liumengdi666 @cxl086
如果从flutter打开native的页面,并接收native的返回值,目前没找到ios端的解决方法。如FlutterBoost.singleton.open('url').then((result)=>{...})的调用
如果从flutter打开native的页面,并接收native的返回值,目前没找到ios端的解决方法。如
FlutterBoost.singleton.open('url').then((result)=>{...})的调用
iOS端关闭页面对应的是[self.navigationController popViewControllerAnimated: YES];
其本身是不带返回值的。所以我理解flutter_boost也因此不提供native关闭页面带返回值的能力。
@MrLittleStrong boost内置的容器(FlutterViewContainer)是实现了这个机制的,已有的原生界面要支持也无需大量代码。FlutterBoost.singleton.open('url').then((result)=>{...})这种机制应该是一种关键特性,如果能通过改动避免自行通过methodChannel实现返回值传递,可以提示开发效率,同时也避免把native的细节暴露到flutter模块。
@noborder 期待官方对这个问题的建议,是否有实现的计划。
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if([call.method isEqual:@"event"]){ NSString *name = call.arguments[@"name"]; NSDictionary *arguments = call.arguments[@"arguments"]; if(name){ NSMutableArray *list = [self lists][name]; if(list){ for(FLBEventListener l in list){ l(name,arguments); } } } } }
FLBEventListener加多一个FlutterResult参数就能实现这个功能,不知道开发组为什么不加。。。
我理解这几个方法都是flutter_boost内部私有方法来负责页面跳转使用的,flutter_boost只负责页面栈的管理。至于flutter与native的其他交互可以创建及使用自己的methodChannel @liumengdi666 @cxl086 是的,可以创建自己的channel,flutter_boost只用来负责页面跳转
您说的private的方法是哪个?可否具体点?
我觉得他的意思应该是这样的:flutter 主动掉原生,原生需要返回结果给 flutter。但是现有的能力只有调用,并不能回传值
您说的private的方法是哪个?可否具体点?
我觉得他的意思应该是这样的:flutter 主动掉原生,原生需要返回结果给 flutter。但是现有的能力只有调用,并不能回传值
https://github.com/alibaba/flutter_boost/issues/781#issue-653801977