Commit 6e0d8ada authored by Jidong Chen's avatar Jidong Chen

remove xservice kit update

parent 55b0aaf8
...@@ -28,8 +28,57 @@ ...@@ -28,8 +28,57 @@
#import "FLBFactory.h" #import "FLBFactory.h"
#import "FLB2Factory.h" #import "FLB2Factory.h"
#import "FLBMessageDispather.h"
#import "FLBMessageImp.h"
#import "NavigationService_closePage.h"
#import "NavigationService_openPage.h"
#import "NavigationService_pageOnStart.h"
#import "NavigationService_onShownContainerChanged.h"
#import "NavigationService_onFlutterPageResult.h"
@interface FlutterBoostPlugin()
@property (nonatomic,strong) FLBMessageDispather *dispatcher;
@end
@implementation FlutterBoostPlugin @implementation FlutterBoostPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_boost"
binaryMessenger:[registrar messenger]];
FlutterBoostPlugin* instance = [self.class sharedInstance];
instance.methodChannel = channel;
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else {
FLBMessageImp *msg = FLBMessageImp.new;
msg.name = call.method;
msg.params = call.arguments;
if(![self.dispatcher dispatch:msg result:result]){
result(FlutterMethodNotImplemented);
}
}
}
- (void)registerHandlers
{
NSArray *handlers = @[
NavigationService_openPage.class,
NavigationService_closePage.class,
NavigationService_pageOnStart.class,
NavigationService_onShownContainerChanged.class,
NavigationService_onFlutterPageResult.class
];
for(Class cls in handlers){
[self.dispatcher registerHandler:cls.new];
}
}
+ (instancetype)sharedInstance + (instancetype)sharedInstance
{ {
static id _instance = nil; static id _instance = nil;
...@@ -45,6 +94,7 @@ ...@@ -45,6 +94,7 @@
{ {
if (self = [super init]) { if (self = [super init]) {
_resultMediator = [FLBResultMediator new]; _resultMediator = [FLBResultMediator new];
[self registerHandlers];
} }
return self; return self;
...@@ -65,23 +115,6 @@ ...@@ -65,23 +115,6 @@
return _factory; return _factory;
} }
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_boost"
binaryMessenger:[registrar messenger]];
FlutterBoostPlugin* instance = [self.class sharedInstance];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else {
result(FlutterMethodNotImplemented);
}
}
- (void)startFlutterWithPlatform:(id<FLB2Platform>)platform - (void)startFlutterWithPlatform:(id<FLB2Platform>)platform
onStart:(void (^)(id<FlutterBinaryMessenger, onStart:(void (^)(id<FlutterBinaryMessenger,
FlutterTextureRegistry, FlutterTextureRegistry,
......
...@@ -37,9 +37,8 @@ ...@@ -37,9 +37,8 @@
- (FLBResultMediator *)resultMediator; - (FLBResultMediator *)resultMediator;
- (id<FLBAbstractFactory>)factory; - (id<FLBAbstractFactory>)factory;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
@property (nonatomic,copy) NSString *fPageId; @property (nonatomic,copy) NSString *fPageId;
@property (nonatomic,copy) NSString *fPagename; @property (nonatomic,copy) NSString *fPagename;
@property (nonatomic,strong) NSDictionary *fParams; @property (nonatomic,strong) NSDictionary *fParams;
@end @end
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_closePage : FlutterServiceCallHandler
@interface NavigationService_closePage : FLBMessageHandlerImp
@end @end
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
//Generated by AIOCodeGen.
#import "ServiceGateway.h" #import "ServiceGateway.h"
#import "NavigationService_closePage.h" #import "NavigationService_closePage.h"
...@@ -48,19 +47,19 @@ ...@@ -48,19 +47,19 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_closePage:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result
[self onCall:result uniqueId:args[@"uniqueId"] pageName:args[@"pageName"] params:args[@"params"] animated:args[@"animated"]]; {
} NSDictionary *args = msg.params;
+ (void)load{ [self onCall:result
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_closePage new]]; uniqueId:args[@"uniqueId"]
pageName:args[@"pageName"]
params:args[@"params"]
animated:args[@"animated"]];
} }
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service
{
return @"NavigationService";
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_onFlutterPageResult : FlutterServiceCallHandler @interface NavigationService_onFlutterPageResult : FLBMessageHandlerImp
@end @end
...@@ -39,19 +39,15 @@ ...@@ -39,19 +39,15 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_onFlutterPageResult:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result
{
NSDictionary *args = msg.params;
[self onCall:result uniqueId:args[@"uniqueId"] key:args[@"key"] resultData:args[@"resultData"] params:args[@"params"]]; [self onCall:result uniqueId:args[@"uniqueId"] key:args[@"key"] resultData:args[@"resultData"] params:args[@"params"]];
} }
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_onFlutterPageResult new]];
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service
{
return @"NavigationService";
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_onShownContainerChanged : FlutterServiceCallHandler @interface NavigationService_onShownContainerChanged : FLBMessageHandlerImp
@end @end
...@@ -38,19 +38,16 @@ ...@@ -38,19 +38,16 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_onShownContainerChanged:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result
{
NSDictionary *args = msg.params;
[self onCall:result newName:args[@"newName"] oldName:args[@"oldName"] params:args[@"params"]]; [self onCall:result newName:args[@"newName"] oldName:args[@"oldName"] params:args[@"params"]];
} }
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_onShownContainerChanged new]];
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service
{
return @"NavigationService";
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_openPage : FlutterServiceCallHandler @interface NavigationService_openPage : FLBMessageHandlerImp
@end @end
...@@ -44,19 +44,15 @@ ...@@ -44,19 +44,15 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_openPage:(NSDictionary *)args result:(void (^)(BOOL))result { - (BOOL)call:(id<FLBMessage>)msg result:(void (^)(BOOL))result{
NSDictionary *args = msg.params;
[self onCall:result pageName:args[@"pageName"] params:args[@"params"] animated:args[@"animated"]]; [self onCall:result pageName:args[@"pageName"] params:args[@"params"] animated:args[@"animated"]];
} }
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_openPage new]];
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"BOOL"; return @"BOOL";
} }
- (NSString *)service
{
return @"NavigationService";
}
@end @end
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
*/ */
// Generated by AIOCodeGen do not edit! // Generated by AIOCodeGen do not edit!
#import "FlutterServiceCallHandler.h" #import "FLBMessageHandlerImp.h"
@interface NavigationService_pageOnStart : FlutterServiceCallHandler @interface NavigationService_pageOnStart : FLBMessageHandlerImp
@end @end
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
//Generated by AIOCodeGen. //Generated by AIOCodeGen.
#import "ServiceGateway.h" #import "ServiceGateway.h"
#import "NavigationService_pageOnStart.h" #import "NavigationService_pageOnStart.h"
#import "FlutterBoostPlugin_private.h" #import "FlutterBoostPlugin_private.h"
@implementation NavigationService_pageOnStart @implementation NavigationService_pageOnStart
...@@ -40,19 +40,16 @@ ...@@ -40,19 +40,16 @@
} }
#pragma mark - Do not edit these method. #pragma mark - Do not edit these method.
- (void)__flutter_p_handler_pageOnStart:(NSDictionary *)args result:(void (^)(NSDictionary *))result {
- (BOOL)call:(id<FLBMessage>)msg result:(void (^)(NSDictionary *))result
{
NSDictionary *args = msg.params;
[self onCall:result params:args[@"params"]]; [self onCall:result params:args[@"params"]];
} }
+ (void)load{
[[ServiceGateway sharedInstance] registerHandler:[NavigationService_pageOnStart new]];
}
- (NSString *)returnType - (NSString *)returnType
{ {
return @"NSDictionary *"; return @"NSDictionary *";
} }
- (NSString *)service
{
return @"NavigationService";
}
@end @end
...@@ -22,10 +22,9 @@ ...@@ -22,10 +22,9 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
//Generated by AIOCodeGen do not edit! #import <Foundation/Foundation.h>
#import "FlutterServiceTemplate.h"
@interface Service_NavigationService : NSObject @interface Service_NavigationService : NSObject
+ (FlutterServiceTemplate *)service;
+ (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params; + (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params;
+ (void)didShowPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId; + (void)didShowPageContainer:(void (^)(NSNumber *))result pageName:(NSString *)pageName params:(NSDictionary *)params uniqueId:(NSString *)uniqueId;
......
...@@ -22,27 +22,16 @@ ...@@ -22,27 +22,16 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
//Generated by AIOCodeGen. Do not edit!
#import "Service_NavigationService.h" #import "Service_NavigationService.h"
#import "ServiceGateway.h" #import <Flutter/Flutter.h>
#import "FlutterServiceTemplate.h" #import "FlutterBoostPlugin_private.h"
@implementation Service_NavigationService @implementation Service_NavigationService
+ (FlutterServiceTemplate *)service + (FlutterMethodChannel *)methodChannel
{ {
static id _instance = nil; return FlutterBoostPlugin.sharedInstance.methodChannel;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[FlutterServiceTemplate alloc] initWithName:@"NavigationService"];
});
return _instance;
}
+ (void)load{
[[ServiceGateway sharedInstance] addService:[self service]];
} }
+ (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params + (void)onNativePageResult:(void (^)(NSNumber *))result uniqueId:(NSString *)uniqueId key:(NSString *)key resultData:(NSDictionary *)resultData params:(NSDictionary *)params
...@@ -52,7 +41,7 @@ ...@@ -52,7 +41,7 @@
if(key) tmp[@"key"] = key; if(key) tmp[@"key"] = key;
if(resultData) tmp[@"resultData"] = resultData; if(resultData) tmp[@"resultData"] = resultData;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
[self.service invoke:@"onNativePageResult" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"onNativePageResult" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -65,7 +54,7 @@ ...@@ -65,7 +54,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"didShowPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"didShowPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -78,7 +67,7 @@ ...@@ -78,7 +67,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"willShowPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"willShowPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -91,7 +80,7 @@ ...@@ -91,7 +80,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"willDisappearPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"willDisappearPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -104,7 +93,7 @@ ...@@ -104,7 +93,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"didDisappearPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"didDisappearPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -117,7 +106,7 @@ ...@@ -117,7 +106,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"didInitPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"didInitPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
...@@ -130,7 +119,7 @@ ...@@ -130,7 +119,7 @@
if(pageName) tmp[@"pageName"] = pageName; if(pageName) tmp[@"pageName"] = pageName;
if(params) tmp[@"params"] = params; if(params) tmp[@"params"] = params;
if(uniqueId) tmp[@"uniqueId"] = uniqueId; if(uniqueId) tmp[@"uniqueId"] = uniqueId;
[self.service invoke:@"willDeallocPageContainer" args:tmp result:^(id tTesult) { [self.methodChannel invokeMethod:@"willDeallocPageContainer" arguments:tmp result:^(id tTesult) {
if (result) { if (result) {
result(tTesult); result(tTesult);
} }
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "FLBMessageing.h"
@interface FLBMessageDispather : NSObject<FLBMessageDispatcher>
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMessageDispather.h"
@interface FLBMessageDispather()
@property (nonatomic,strong) NSMutableDictionary *handlerMap;
@end
@implementation FLBMessageDispather
- (instancetype)init
{
if (self = [super init]) {
_handlerMap = NSMutableDictionary.new;
}
return self;
}
- (BOOL)dispatch:(id<FLBMessage>)msg result:(void (^)(id date))result
{
if (msg) {
id<FLBMessageHandler> handler = _handlerMap[msg.name];
return [handler handle:msg result:result];
}else{
return NO;
}
}
- (void)registerHandler:(id<FLBMessageHandler>)handler
{
if(!handler) return;
NSArray *methods = handler.handledMessageNames;
for(NSString *name in methods){
if(_handlerMap[name]){
NSAssert(NO, @"Conflicted method call name results in undefined error!");
}else{
_handlerMap[name] = handler;
}
}
}
- (void)removeHandler:(id<FLBMessageHandler>)handler
{
NSArray *methods = handler.handledMessageNames;
[_handlerMap removeObjectsForKeys:methods];
}
- (void)removeAll
{
[_handlerMap removeAllObjects];
}
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "FLBMessageing.h"
@interface FLBMessageHandlerImp : NSObject<FLBMessageHandler>
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMessageHandlerImp.h"
typedef void (^SendResult)(NSObject *result);
@interface FLBMessageHandlerImp()
@property (nonatomic,strong) NSMutableDictionary *callHandlers;
@property (nonatomic,strong) NSMutableArray *methodNames;
@end
@implementation FLBMessageHandlerImp
- (instancetype)init{
if (self = [super init]) {
_callHandlers = [NSMutableDictionary new];
_methodNames = NSMutableArray.new;
[self bindCallMethod];
}
return self;
}
#pragma mark - method handling logic.
//Farward this msg to old entry.
- (BOOL)handle:(id<FLBMessage>)msg result:(void (^)(id data))result
{
return [self handleMethodCall:msg.name args:msg.params result:result];
}
- (NSArray *)handledMessageNames
{
return _methodNames;
}
- (bool)handleMethodCall:(NSString*)call
args:(NSDictionary *)args
result:(void (^)(id data))result
{
void (^handler)(NSDictionary *,SendResult) = [self findHandler:call];
if (handler) {
handler(args,result);
return YES;
}
return NO;
}
- (id)findHandler:(NSString *)call
{
return _callHandlers[call];
}
- (void)bindCallMethod
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
SEL method = @selector(call:result:);
if (_callHandlers[NSStringFromSelector(method)]) {
return;
}
__weak typeof(self) weakSelf = self;
_callHandlers[NSStringFromSelector(method)] = ^(NSDictionary *args,SendResult result){
id resultBlock = [weakSelf getHandlerBlockForType:weakSelf.returnType result:result];
if (resultBlock && result) {
[weakSelf performSelector:method withObject:args withObject:resultBlock];
}else{
#if DEBUG
[NSException raise:@"invalid call" format:@"missing handler and result!"];
#endif
}
};
#pragma clang diagnostic pop
}
- (id)getHandlerBlockForType:(NSString *)type result:(SendResult)result
{
if ([type isEqual:@"int64_t"]) {
return ^(int64_t value){
result(@(value));
};
}
if ([type isEqual:@"double"]) {
return ^(double value){
result(@(value));
};
}
if ([type isEqual:@"BOOL"]) {
return ^(BOOL value){
result(@(value));
};
}
if ([type hasPrefix:@"NSString"]) {
return ^(NSString *value){
if ([value isKindOfClass:NSNumber.class]) {
#if DEBUG
[NSException raise:@"invalid type" format:@"require NSString!"];
#endif
value = ((NSNumber *)value).stringValue;
}
result(value);
};
}
if ([type hasPrefix:@"NSArray"]) {
return ^(NSArray *value){
result(value);
};
}
if ([type hasPrefix:@"NSDictionary"]) {
return ^(NSDictionary *value){
result(value);
};
}
if ([type isEqual:@"id"]) {
return result;
}
/*
@"int":@"int64_t",
@"double":@"double",
@"bool":@"BOOL",
@"String":@"NSString *",
*/
return nil;
}
- (NSString *)returnType
{
return @"id";
}
- (NSString *)service
{
return @"root";
}
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import "FLBMessageing.h"
NS_ASSUME_NONNULL_BEGIN
@interface FLBMessageImp : NSObject<FLBMessage>
@property (nonatomic,copy) NSString *name;
@property (nonatomic,strong) NSDictionary *params;
@end
NS_ASSUME_NONNULL_END
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "FLBMessageImp.h"
@implementation FLBMessageImp
- (NSString *)name
{
return _name;
}
- (NSDictionary *)params
{
return _params;
}
@end
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
@protocol FLBMessage <NSObject>
@required
- (NSString *)name;
- (NSDictionary *)params;
@end
@protocol FLBMessageHandler <NSObject>
@required
- (BOOL)handle:(id<FLBMessage>)msg result:(void (^)(id result))result;
- (NSArray *)handledMessageNames;
- (NSString *)service;
@end
@protocol FLBMessageDispatcher <NSObject>
@required
- (BOOL)dispatch:(id<FLBMessage>)msg result:(void (^)(id result))result;
- (void)registerHandler:(id<FLBMessageHandler>) handler;
- (void)removeHandler:(id<FLBMessageHandler>) handler;
- (void)removeAll;
@end
...@@ -25,8 +25,6 @@ A new Flutter plugin make flutter better to use! ...@@ -25,8 +25,6 @@ A new Flutter plugin make flutter better to use!
'Classes/1.5/FLB2FlutterViewContainer.h' 'Classes/1.5/FLB2FlutterViewContainer.h'
s.dependency 'Flutter' s.dependency 'Flutter'
s.dependency 'xservice_kit'
s.libraries = 'c++' s.libraries = 'c++'
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
......
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