Permalink
Browse files

Don't assume that the webview delegate has implemented all the WebVie…

…wDelegate protocol selectors
  • Loading branch information...
1 parent f3e90bf commit ff0ea9d707bbd779a1c32e2fcc10823980d57e98 @marcuswestin committed Nov 19, 2012
Showing with 4 additions and 4 deletions.
  1. +4 −4 WebViewJavascriptBridge/WebViewJavascriptBridge.m
View
8 WebViewJavascriptBridge/WebViewJavascriptBridge.m
@@ -198,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];
}
}
@@ -220,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;
@@ -229,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];
}
}

0 comments on commit ff0ea9d

Please sign in to comment.