From 896e9aaa5159586069d2af0206e5dcf872c66131 Mon Sep 17 00:00:00 2001 From: Insomnia <282132315@qq.com> Date: Thu, 31 Oct 2019 23:46:10 +0800 Subject: [PATCH] add: invokeObject --- .../Classes/Engine/DoricJSRemoteExecutor.m | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m b/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m index b49a015d..bd085a2f 100644 --- a/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m +++ b/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m @@ -28,7 +28,6 @@ @interface DoricJSRemoteExecutor () @property(nonatomic, strong) NSMapTable *mapTable; @property(nonatomic, strong) SRWebSocket *websocket; - @end @implementation DoricJSRemoteExecutor @@ -83,11 +82,35 @@ - (void)injectGlobalJSObject:(NSString *)name obj:(id)obj { - (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(NSArray *)args { + NSMutableArray *argsMArr = [NSMutableArray new]; + for (id arg in args) { + NSDictionary *dic = @{ + @"type": [arg class], + @"value": arg + }; + [argsMArr addObject:dic]; + } + + NSDictionary *jsonDic = @{ + @"cmd": @"invokeMethod", + @"obj": objName, + @"functionName": funcName, + @"javaValues": argsMArr + }; + + NSError * err; + NSData * jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:0 error:&err]; + if (err) { + DoricLog(@"debugger ", NSStringFromSelector(_cmd), @" failed"); + } + + [self.websocket send:jsonData]; + dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER); + return nil; } #pragma mark - Properties - - (SRWebSocket *)websocket { if (!_websocket) { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:kUrlStr] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];