Latest 0.1.1
License MIT
Platforms ios 9.0

This Swift module is the native part of a RPC communication bridge between your app and a webview javascript.
It is designed to work together with its javascript counterpart, nrkno/nativebridge.


In addition to nrkno/nativebridge, nativebridge-ios relies on WKWebView and script message handlers to work.


nativebridge-ios is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'nativebridge-ios'


To run the example project, clone the repo, and run pod install from the Example directory first.


All communication with the javascript is managed through the WebViewConnnection class.

Communication follows a protocol where messages are sent back and forth between the javascript and your code.
Messages have a topic, and some data.
The data must implement the Codable protocol.

Establishing the javscript connection

One must configure the WKWebView instance by adding a script message handler (WKScriptMessageHandler) that will listen to messages sent to ‘nativebridgeiOS’.

See the example project for details on how to do this.

Sending data

let data = SomeDataType()
webViewConnection.send(data: data, for: Topic.someTopic)

Adding topic handlers

In order to react on messages sent from the javascript, one must add handlers to the WebViewConnnection instance:

webViewConnection.addHandler(for Topic.someTopic, {
    (input: InputDataType, connection) in {
        let message = "Received incoming: '(input.inputMessage)'"
        let output = OutputData(outputMessage: message)
        connection.send(data: output, for: Topic.someTopic)


nativebridge-ios is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "nativebridge-ios",
    "version": "0.1.1",
    "summary": "The native part of a communication bridge between javascript running in a WKWebView and your app.",
    "description": "When used together with its javascript counterpart, 'nativebridge', this framework enables communication betweennyour app and the javascript hosted in a WKWebView.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "NRK Medieutvikling": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.1"
    "module_name": "NativeBridge",
    "platforms": {
        "ios": "9.0"
    "source_files": "nativebridge-ios/Classes/**/*",
    "ios": {
        "frameworks": "WebKit"

Pin It on Pinterest

Share This