You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log("JS received response:", responseData)
110
109
})
111
110
})
112
111
```
113
112
114
-
WKWebView Support (iOS 8 & OS 10.10)
115
-
------------------------------------
113
+
WKWebView Support (iOS 8+ & OS 10.10+)
114
+
--------------------------------------
116
115
117
116
WARNING: WKWebView still has [many bugs and missing network APIs.](https://github.com/ShingoFukuyama/WKWebViewTips/blob/master/README.md) It may not be a simple drop-in replacement.
118
117
@@ -128,10 +127,7 @@ WebViewJavascriptBridge supports [WKWebView](http://nshipster.com/wkwebkit/) for
128
127
2) Instantiate WKWebViewJavascriptBridge and with a WKWebView object
Create a javascript bridge for the given web view.
152
147
153
-
The `WVJBResponseCallback` will not be `nil` if the javascript expects a response.
154
-
155
-
Optionally, pass in `webViewDelegate:(UIWebViewDelegate*)webViewDelegate` if you need to respond to the [web view's lifecycle events](http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html).
`WebViewJavascriptBridge` requires `WebViewJavascriptBridge.js.txt` file that is injected into web view to create a bridge on JS side. Standard implementation uses `mainBundle` to search for this file. If you e.g. build a static library and you have that file placed somewhere else you can use this method to specify which bundle should be searched for `WebViewJavascriptBridge.js.txt` file:
##### `document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) { ... }, false)`
186
+
Optionally, set a `UIWebViewDelegate` if you need to respond to the [web view's lifecycle events](http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html).
231
187
232
-
Always wait for the `WebViewJavascriptBridgeReady` DOM event.
Initialize the bridge. This should be called inside of the `'WebViewJavascriptBridgeReady'` event handler.
191
+
### Javascript API
246
192
247
-
The `messageHandler` function will receive all messages sent from ObjC via `[bridge send:(id)data]` and `[bridge send:(id)data responseCallback:(WVJBResponseCallback)responseCallback]`.
The `response` object will be defined if if ObjC sent the message with a `WVJBResponseCallback` block.
195
+
Register a handler called `handlerName`. The ObjC can then call this handler with `[bridge callHandler:"handlerName" data:@"Foo"]` and `[bridge callHandler:"handlerName" data:@"Foo" responseCallback:^(id responseData) { ... }]`
Register a handler called `handlerName`. The ObjC can then call this handler with `[bridge callHandler:"handlerName" data:@"Foo"]` and `[bridge callHandler:"handlerName" data:@"Foo" responseCallback:^(id responseData) { ... }]`
209
+
Call an ObjC handler called `handlerName`. If `responseCallback` is defined, the ObjC handler can respond.
0 commit comments