WebViewBridge.Swift

swift

Like JockeyJS, written in Swift, and with support for WKWebView:

A bridge for WebView(UIWebView, WKWebView), using JavaScriptCore, handles communications between native(Swift) and js.

Example usage (call native function from JS):

// XCode
override func viewDidLoad() {

    // …

    let webView = WKWebView()
    let bridge = ZHWebViewBridge.bridge(webview)

    bridge.registerHandler("Video.Play") { (args:[AnyObject]) -> (Bool, [AnyObject]?) in
        self.player.play()
        return (true, nil)
    }

    // …
}
// JavaScript
<-- orig source: /Pods/WebViewBridge.Swift/Sources/bridge.js -->
<script src="bridge.js"></script>
<script>
    ZHBridge.Core.ready(function() {
        ZHBridge.Core.callNativeHandler('Video.Play');
    });
</script>

WebViewBridge.Swift →

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.