File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 2222 #define WVJB_WEBVIEW_DELEGATE_TYPE NSObject <UIWebViewDelegate>
2323#endif
2424
25+ @protocol WebViewJavascriptBridgeDelegate <NSObject >
26+
27+ @optional
28+
29+ // define a method,make the user decide every request from webview should be load except the WVJB request
30+ -(BOOL ) WVJB_webView : (UIWebView *)webView
31+ shouldStartLoadWithRequest : (NSURLRequest *)request
32+ navigationType : (UIWebViewNavigationType)navigationType ;
33+
34+
35+ @end
36+
2537typedef void (^WVJBResponseCallback)(id responseData);
2638typedef void (^WVJBHandler)(id data, WVJBResponseCallback responseCallback);
2739
2840@interface WebViewJavascriptBridge : WVJB _WEBVIEW_DELEGATE_TYPE
2941
42+ @property (nonatomic ,weak ) id <WebViewJavascriptBridgeDelegate> delegate;
43+
3044+ (instancetype )bridgeForWebView : (WVJB_WEBVIEW_TYPE*)webView handler : (WVJBHandler)handler ;
3145+ (instancetype )bridgeForWebView : (WVJB_WEBVIEW_TYPE*)webView webViewDelegate : (WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler : (WVJBHandler)handler ;
46+ + (instancetype )bridgeForWebView : (WVJB_WEBVIEW_TYPE*)webView WVJBDelegate : (id )delegate handler : (WVJBHandler)handler ;
3247+ (instancetype )bridgeForWebView : (WVJB_WEBVIEW_TYPE*)webView webViewDelegate : (WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler : (WVJBHandler)handler resourceBundle : (NSBundle *)bundle ;
3348+ (void )enableLogging ;
3449
Original file line number Diff line number Diff line change @@ -52,6 +52,15 @@ + (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WV
5252 WebViewJavascriptBridge* bridge = [[WebViewJavascriptBridge alloc ] init ];
5353 [bridge _platformSpecificSetup: webView webViewDelegate: webViewDelegate handler: messageHandler resourceBundle: bundle];
5454 [bridge reset ];
55+ bridge.delegate = nil ;
56+ return bridge;
57+ }
58+
59+ + (instancetype )bridgeForWebView : (WVJB_WEBVIEW_TYPE*)webView WVJBDelegate : (id )delegate handler : (WVJBHandler)handler {
60+ WebViewJavascriptBridge* bridge = [[WebViewJavascriptBridge alloc ] init ];
61+ [bridge _platformSpecificSetup: webView webViewDelegate: nil handler: handler];
62+ [bridge reset ];
63+ bridge.delegate = delegate;
5564 return bridge;
5665}
5766
@@ -387,7 +396,17 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
387396 } else if (strongDelegate && [strongDelegate respondsToSelector: @selector (webView:shouldStartLoadWithRequest:navigationType: )]) {
388397 return [strongDelegate webView: webView shouldStartLoadWithRequest: request navigationType: navigationType];
389398 } else {
390- return YES ;
399+ if (self.delegate ){
400+ if ([self .delegate respondsToSelector: @selector (WVJB_webView:shouldStartLoadWithRequest:navigationType: )]){
401+ return [self .delegate WVJB_webView: webView
402+ shouldStartLoadWithRequest: request
403+ navigationType: navigationType];
404+ }else {
405+ return YES ;
406+ }
407+ }else {
408+ return YES ;
409+ }
391410 }
392411}
393412
You can’t perform that action at this time.
0 commit comments