Commit f5629d29 authored by 余玠's avatar 余玠

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

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