Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: marcuswestin/WebViewJavascriptBridge
base: 60aa43be10
...
head fork: marcuswestin/WebViewJavascriptBridge
compare: 318e72acf9
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
View
1  WebViewJavascriptBridge/WebViewJavascriptBridge.h
@@ -14,6 +14,7 @@ typedef void (^WVJBHandler)(id data, WVJBResponse* response);
- (void)callHandler:(NSString*)handlerName;
- (void)callHandler:(NSString*)handlerName data:(id)data;
- (void)callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)responseCallback;
+- (void)reset;
@end
@interface WVJBResponse : NSObject
View
20 WebViewJavascriptBridge/WebViewJavascriptBridge.m
@@ -37,12 +37,10 @@ + (id)bridgeForWebView:(UIWebView *)webView handler:(WVJBHandler)handler {
+ (id)bridgeForWebView:(UIWebView *)webView webViewDelegate:(id<UIWebViewDelegate>)webViewDelegate handler:(WVJBHandler)messageHandler {
WebViewJavascriptBridge* bridge = [[WebViewJavascriptBridge alloc] init];
bridge.messageHandler = messageHandler;
- bridge.startupMessageQueue = [NSMutableArray array];
- bridge.responseCallbacks = [NSMutableDictionary dictionary];
- bridge.messageHandlers = [NSMutableDictionary dictionary];
- bridge.uniqueId = 0;
bridge.webView = webView;
bridge.webViewDelegate = webViewDelegate;
+ bridge.messageHandlers = [NSMutableDictionary dictionary];
+ [bridge reset];
webView.delegate = bridge;
return bridge;
}
@@ -74,6 +72,12 @@ - (void)registerHandler:(NSString *)handlerName handler:(WVJBHandler)handler {
[self.messageHandlers setObject:handler forKey:handlerName];
}
+- (void)reset {
+ self.startupMessageQueue = [NSMutableArray array];
+ self.responseCallbacks = [NSMutableDictionary dictionary];
+ self.uniqueId = 0;
+}
+
- (void)_sendData:(NSDictionary *)data responseCallback:(WVJBResponseCallback)responseCallback handlerName:(NSString*)handlerName {
NSMutableDictionary* message = [NSMutableDictionary dictionaryWithObject:data forKey:@"data"];
@@ -194,14 +198,14 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView {
self.startupMessageQueue = nil;
}
- if (self.webViewDelegate) {
+ if (self.webViewDelegate && [self.webViewDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
[self.webViewDelegate webViewDidFinishLoad:webView];
}
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if (webView != _webView) { return; }
- if (self.webViewDelegate) {
+ if (self.webViewDelegate && [self.webViewDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
[self.webViewDelegate webView:_webView didFailLoadWithError:error];
}
}
@@ -216,7 +220,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
NSLog(@"WebViewJavascriptBridge: WARNING: Received unknown WebViewJavascriptBridge command %@://%@", CUSTOM_PROTOCOL_SCHEME, [url path]);
}
return NO;
- } else if (self.webViewDelegate) {
+ } else if (self.webViewDelegate && [self.webViewDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) {
return [self.webViewDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
} else {
return YES;
@@ -225,7 +229,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
- (void)webViewDidStartLoad:(UIWebView *)webView {
if (webView != _webView) { return; }
- if (self.webViewDelegate) {
+ if (self.webViewDelegate && [self.webViewDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
[self.webViewDelegate webViewDidStartLoad:webView];
}
}

No commit comments for this range

Something went wrong with that request. Please try again.