Skip to content

Commit

Permalink
Improve documentation of new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuswestin committed Jan 29, 2016
1 parent ff14c14 commit ac4e73d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ Usage
2) Instantiate WebViewJavascriptBridge with a UIWebView (iOS) or WebView (OSX):

```objc
self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView handler:^(id data, WVJBResponseCallback responseCallback) {
NSLog(@"Received message from javascript: %@", data);
responseCallback(@"Right back atcha");
}];
self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView];
```
3) Go ahead and send some messages from ObjC to javascript:
3) Register a handler in ObjC, and call a JS handler:
```objc
[self.bridge registerHandler:@"ObjC Echo" handler:^(id data, WVJBResponseCallback responseCallback) {
Expand All @@ -70,7 +67,7 @@ self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView handler:^(id dat
}];
```

4) Finally, set up the javascript side:
4) Copy and paste `setupWebViewJavascriptBridge` into your JS:

```javascript
function setupWebViewJavascriptBridge(callback) {
Expand All @@ -83,7 +80,11 @@ function setupWebViewJavascriptBridge(callback) {
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
```

5) Finally, call `setupWebViewJavascriptBridge` and then use the bridge to register handlers and call ObjC handlers:

```javascript
setupWebViewJavascriptBridge(function(bridge) {

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


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

Call an ObjC handler called `handlerName`. If `responseCallback` is defined, the ObjC handler can respond.
Call an ObjC handler called `handlerName`. If a `responseCallback` function is given the ObjC handler can respond.

Example:

Expand Down

0 comments on commit ac4e73d

Please sign in to comment.