Skip to content

Commit ac4e73d

Browse files
committed
Improve documentation of new APIs
1 parent ff14c14 commit ac4e73d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,10 @@ Usage
5252
2) Instantiate WebViewJavascriptBridge with a UIWebView (iOS) or WebView (OSX):
5353

5454
```objc
55-
self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView handler:^(id data, WVJBResponseCallback responseCallback) {
56-
NSLog(@"Received message from javascript: %@", data);
57-
responseCallback(@"Right back atcha");
58-
}];
55+
self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView];
5956
```
6057
61-
3) Go ahead and send some messages from ObjC to javascript:
58+
3) Register a handler in ObjC, and call a JS handler:
6259
6360
```objc
6461
[self.bridge registerHandler:@"ObjC Echo" handler:^(id data, WVJBResponseCallback responseCallback) {
@@ -70,7 +67,7 @@ self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView handler:^(id dat
7067
}];
7168
```
7269

73-
4) Finally, set up the javascript side:
70+
4) Copy and paste `setupWebViewJavascriptBridge` into your JS:
7471

7572
```javascript
7673
function setupWebViewJavascriptBridge(callback) {
@@ -83,7 +80,11 @@ function setupWebViewJavascriptBridge(callback) {
8380
document.documentElement.appendChild(WVJBIframe);
8481
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
8582
}
83+
```
8684

85+
5) Finally, call `setupWebViewJavascriptBridge` and then use the bridge to register handlers and call ObjC handlers:
86+
87+
```javascript
8788
setupWebViewJavascriptBridge(function(bridge) {
8889

8990
/* Initialize your app here */
@@ -158,7 +159,7 @@ Example:
158159
##### `[bridge callHandler:(NSString*)handlerName data:(id)data]`
159160
##### `[bridge callHandler:(NSString*)handlerName data:(id)data responseCallback:(WVJBResponseCallback)callback]`
160161
161-
Call the javascript handler called `handlerName`. Optionally expect a response by giving a `responseCallback` block.
162+
Call the javascript handler called `handlerName`. If a `responseCallback` block is given the javascript handler can respond.
162163
163164
Example:
164165
@@ -192,9 +193,10 @@ bridge.registerHandler("getCurrentPageUrl", function(data, responseCallback) {
192193
```
193194

194195

196+
##### `bridge.callHander("handlerName", data)`
195197
##### `bridge.callHander("handlerName", data, function responseCallback(responseData) { ... })`
196198

197-
Call an ObjC handler called `handlerName`. If `responseCallback` is defined, the ObjC handler can respond.
199+
Call an ObjC handler called `handlerName`. If a `responseCallback` function is given the ObjC handler can respond.
198200

199201
Example:
200202

0 commit comments

Comments
 (0)