marcuswestin/WebViewJavascriptBridge — pull request #105 by lokimeyburg (2014-10-15 03:49:21+00:00)
Title: WKWebView Support

I've added support for [WKWebView](http://nshipster.com/wkwebkit/) which was requested in issue #84.

**How does it work:**
WKWebView support is op-tin. In order to use WKWebView you need to instantiate the `WKWebViewJavascriptBridge`. The rest of the `WKWebViewJavascriptBridge` API is the same as `WebViewJavascriptBridge`.

1) Import the header file:

```
#import "WKWebViewJavascriptBridge.h"
```

2) Instantiate WKWebViewJavascriptBridge and with a WKWebView object

WKWebViewJavascriptBridge* bridge = [WKWebViewJavascriptBridge bridgeForWebView:webView handler:^(id data, WVJBResponseCallback responseCallback) {
// etc
}];

**Where to start**
Take a look at the `WKWebViewJavascriptBridge.m` file first as it has most of the logic. The two important differences are that the delegates for WKWebView have been changed and that the response for evaluating Javascript is now returned in a callback.

| UIWebView | WKWebView Equivalent |
--- | --- | ---
| didFailLoadWithError | didFailNavigation |
| webViewDidFinishLoad | didFinishNavigation |
| webViewDidStartLoad | didStartProvisionalNavigation |
| shouldStartLoadWithRequest | decidePolicyForNavigationAction |

**How to test this**
Pull down the branch and try to run the example application. Try running it in XCode 5 and 6 to test out iOS7 and iOS8 respectively. If you're using Pods, point to this branch and see if it works in one of your existing apps.

**Extra**

1. Can someone please test this out on OSX 10.10? I don't have a machine currently running Yosemite.
2. I'm also currently testing this against a bigger iOS project, [Stacker](http://www.lokimeyburg.com/Stacker/), in the [`feature/wkwebkit`](https://github.com/lokimeyburg/Stacker/tree/feature/wkwebview/Example) branch to make sure WebViewJavascriptBridge works as advertised.
3. I think there's lots of room to DRY up the code between `WebViewJavascriptBridge` and `WKWebViewJavascriptBridge` however I think that should be left for another PR.