Skip to content

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.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Feb 09, 2014
Kamil Burczyk Added possibility to set custom bundle where core bridge.js script is…
… located
5183c4c
Commits on Feb 10, 2014
@marcuswestin Merge pull request #68 from burczyk/feature/custombundle
Added possibility to set custom bundle where core WebViewJavascriptBridge.js script is located.
47d9a9a
View
1 WebViewJavascriptBridge/WebViewJavascriptBridge.h
@@ -29,6 +29,7 @@ typedef void (^WVJBHandler)(id data, WVJBResponseCallback responseCallback);
+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView handler:(WVJBHandler)handler;
+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)handler;
++ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)handler resourceBundle:(NSBundle*)bundle;
+ (void)enableLogging;
- (void)send:(id)message;
View
22 WebViewJavascriptBridge/WebViewJavascriptBridge.m
@@ -25,6 +25,8 @@ @implementation WebViewJavascriptBridge {
long _uniqueId;
WVJBHandler _messageHandler;
+ NSBundle *_resourceBundle;
+
#if defined WVJB_PLATFORM_IOS
NSUInteger _numRequestsLoading;
#endif
@@ -42,8 +44,13 @@ + (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView handler:(WVJBHandle
}
+ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler {
+ return [self bridgeForWebView:webView webViewDelegate:webViewDelegate handler:messageHandler resourceBundle:nil];
+}
+
++ (instancetype)bridgeForWebView:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle
+{
WebViewJavascriptBridge* bridge = [[WebViewJavascriptBridge alloc] init];
- [bridge _platformSpecificSetup:webView webViewDelegate:webViewDelegate handler:messageHandler];
+ [bridge _platformSpecificSetup:webView webViewDelegate:webViewDelegate handler:messageHandler resourceBundle:bundle];
[bridge reset];
return bridge;
}
@@ -222,7 +229,7 @@ - (void)_log:(NSString *)action json:(id)json {
**********************************/
#if defined WVJB_PLATFORM_OSX
-- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler {
+- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)webViewDelegate handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle{
_messageHandler = messageHandler;
_webView = webView;
_webViewDelegate = webViewDelegate;
@@ -231,6 +238,8 @@ - (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(WVJ
_webView.frameLoadDelegate = self;
_webView.resourceLoadDelegate = self;
_webView.policyDelegate = self;
+
+ _resourceBundle = bundle;
}
- (void) _platformSpecificDealloc {
@@ -244,7 +253,8 @@ - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)frame
if (webView != _webView) { return; }
if (![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) {
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"];
+ NSBundle *bundle = _resourceBundle ? _resourceBundle : [NSBundle mainBundle];
+ NSString *filePath = [bundle pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"];
NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:js];
}
@@ -312,12 +322,13 @@ - (NSURLRequest *)webView:(WebView *)webView resource:(id)identifier willSendReq
**********************************/
#elif defined WVJB_PLATFORM_IOS
-- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(id<UIWebViewDelegate>)webViewDelegate handler:(WVJBHandler)messageHandler {
+- (void) _platformSpecificSetup:(WVJB_WEBVIEW_TYPE*)webView webViewDelegate:(id<UIWebViewDelegate>)webViewDelegate handler:(WVJBHandler)messageHandler resourceBundle:(NSBundle*)bundle{
_messageHandler = messageHandler;
_webView = webView;
_webViewDelegate = webViewDelegate;
_messageHandlers = [NSMutableDictionary dictionary];
_webView.delegate = self;
+ _resourceBundle = bundle;
}
- (void) _platformSpecificDealloc {
@@ -330,7 +341,8 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView {
_numRequestsLoading--;
if (_numRequestsLoading == 0 && ![[webView stringByEvaluatingJavaScriptFromString:@"typeof WebViewJavascriptBridge == 'object'"] isEqualToString:@"true"]) {
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"];
+ NSBundle *bundle = _resourceBundle ? _resourceBundle : [NSBundle mainBundle];
+ NSString *filePath = [bundle pathForResource:@"WebViewJavascriptBridge.js" ofType:@"txt"];
NSString *js = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:js];
}

No commit comments for this range

Something went wrong with that request. Please try again.