Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在js和native里都添加两个共同处理 #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ - (void)flushMessageQueue:(NSString *)messageQueueString{

if (!handler) {
NSLog(@"WVJBNoHandlerException, No handler for message from JS: %@", message);
continue;
//continue;
if (responseCallback) {
// 如果是获取所有method的方法列表
if ([@"allNativeMethodsImplementationForJs" isEqualToString:message[@"handlerName"]]) {
NSArray *handlerNames = self.messageHandlers.allKeys;
if(handlerNames == nil){
handlerNames = @[];
}
responseCallback(handlerNames);
}else{
responseCallback(@"NoMethodInNative");
}

}
}

handler(message[@"data"], responseCallback);
Expand Down
12 changes: 12 additions & 0 deletions WebViewJavascriptBridge/WebViewJavascriptBridge_JS.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ function _doDispatchMessageFromObjC() {
var handler = messageHandlers[message.handlerName];
if (!handler) {
console.log("WebViewJavascriptBridge: WARNING: no handler for message from ObjC:", message);
if (responseCallback) {
if ("AllMethodsImplementationInJs" == message.handlerName) {
var keys = [];
for (var handlerName in messageHandlers){
keys.push(handlerName);
}
responseCallback(keys);
}else{
responseCallback("NoMethodInJs");
}

}
} else {
handler(message.data, responseCallback);
}
Expand Down