Commit f5629d29 authored by 余玠's avatar 余玠

fixbug: 实现页面返回数据逻辑

parent 06866ee5
......@@ -19,7 +19,7 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
DemoRouter *router = [DemoRouter sharedRouter];
DemoRouter *router = [DemoRouter new];
[FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router
onStart:^(FlutterEngine *engine) {
......
......@@ -15,12 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol FLBPlatform;
@interface DemoRouter : NSObject<FLBPlatform>
@property (nonatomic,strong) UINavigationController *navigationController;
+ (DemoRouter *)sharedRouter;
@end
NS_ASSUME_NONNULL_END
......@@ -9,17 +9,10 @@
#import "DemoRouter.h"
#import <flutter_boost/FlutterBoost.h>
@implementation DemoRouter
@interface DemoRouter()
@end
+ (DemoRouter *)sharedRouter
{
static id instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
@implementation DemoRouter
#pragma mark - Boost 1.5
- (void)open:(NSString *)name
......@@ -56,27 +49,4 @@
[self.navigationController popViewControllerAnimated:animated];
}
}
#pragma mark - Boost 1.0 - deprecated~
- (void)openPage:(NSString *)name
params:(NSDictionary *)params
animated:(BOOL)animated
completion:(void (^)(BOOL))completion
{
NSMutableDictionary *exts = NSMutableDictionary.new;
exts[@"url"] = name;
exts[@"params"] = params;
exts[@"animated"] = @(animated);
[self open:name urlParams:params exts:exts completion:completion];
return;
}
- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion
{
NSMutableDictionary *exts = NSMutableDictionary.new;
exts[@"params"] = params;
exts[@"animated"] = @(animated);
[self close:uid result:@{} exts:exts completion:completion];
return;
}
@end
......@@ -24,20 +24,19 @@
}
- (IBAction)pushFlutterPage:(id)sender {
[DemoRouter.sharedRouter open:@"first"
urlParams:@{}
exts:@{@"animated":@(YES)}
completion:^(BOOL f){
[FlutterBoostPlugin open:@"first" urlParams:@{kPageCallBackId:@"MycallbackId#1"} exts:@{@"animated":@(YES)} reult:^(NSDictionary *result) {
NSLog(@"call me when page finished, and your result is:%@", result);
} completion:^(BOOL f) {
NSLog(@"page is opened");
}];
}
- (IBAction)present:(id)sender {
[DemoRouter.sharedRouter open:@"second"
urlParams:@{@"present":@(YES)}
exts:@{@"animated":@(YES)}
completion:^(BOOL f){}];
// [self dismissViewControllerAnimated:YES completion:completion];
[FlutterBoostPlugin open:@"second" urlParams:@{@"present":@(YES),kPageCallBackId:@"MycallbackId#2"} exts:@{@"animated":@(YES)} reult:^(NSDictionary *result) {
NSLog(@"call me when page finished, and your result is:%@", result);
} completion:^(BOOL f) {
NSLog(@"page is presented");
}];
}
/*
......
......@@ -24,6 +24,8 @@
#import <Foundation/Foundation.h>
#define kPageCallBackId @"__callback_id__"
NS_ASSUME_NONNULL_BEGIN
@protocol FLBPlatform <NSObject>
@optional
......
......@@ -44,4 +44,16 @@
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name;
#pragma mark - open/close Page
+ (void)close:(NSString *)uniqueId
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion;
+ (void)open:(NSString *)url
urlParams:(NSDictionary *)urlParams
exts:(NSDictionary *)exts
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion;
@end
......@@ -162,4 +162,14 @@
forName:name];
}
#pragma mark - open/close Page
+ (void)open:(NSString *)url urlParams:(NSDictionary *)urlParams exts:(NSDictionary *)exts reult:(void (^)(NSDictionary *))resultCallback completion:(void (^)(BOOL))completion{
id<FLBFlutterApplicationInterface> app = [[FlutterBoostPlugin sharedInstance] application];
[app open:url urlParams:urlParams exts:exts reult:resultCallback completion:completion];
}
+ (void)close:(NSString *)uniqueId result:(NSDictionary *)result exts:(NSDictionary *)exts completion:(void (^)(BOOL))completion{
id<FLBFlutterApplicationInterface> app = [[FlutterBoostPlugin sharedInstance] application];
[app close:uniqueId result:result exts:exts completion:completion];
}
@end
......@@ -30,7 +30,7 @@
- (id<FLBFlutterApplicationInterface>)createApplication:(id<FLBPlatform>)platform
{
return FLBFlutterApplication.new;
return [FLBFlutterApplication sharedApplication];
}
- (id<FLBFlutterContainer>)createFlutterContainer
......
......@@ -30,6 +30,6 @@
NS_ASSUME_NONNULL_BEGIN
@interface FLBFlutterApplication : NSObject<FLBFlutterApplicationInterface>
@property (nonatomic,strong) id<FLBPlatform> platform;
+ (FLBFlutterApplication *)sharedApplication;
@end
NS_ASSUME_NONNULL_END
......@@ -37,6 +37,7 @@
@implementation FLBFlutterApplication
@synthesize platform;
+ (FLBFlutterApplication *)sharedApplication
{
......@@ -173,7 +174,7 @@
reult:(void (^)(NSDictionary *))resultCallback
completion:(void (^)(BOOL))completion
{
NSString *cid = urlParams[@"__calback_id__"];
NSString *cid = urlParams[kPageCallBackId];
if(!cid){
static int64_t sCallbackID = 1;
......@@ -193,7 +194,7 @@
params:(NSDictionary *)urlParams
uniqueId:(NSString *)uniqueId
{
NSString *cid = urlParams[@"__calback_id__"];
NSString *cid = urlParams[kPageCallBackId];
if(cid && _callbackCache[cid]){
_pageResultCallbacks[uniqueId] = _callbackCache[cid];
[_callbackCache removeObjectForKey:cid];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment