Latest 1.0.0
License MIT
Platforms ios 6.0

Easy way to communicate between Cocoa code and JavaScript code in a


The demo/ folder contains a demo project showing
UIViewController+JSBridge in use. Open and run it.


Add the following import to your ViewController that contains the

#import "UIViewController+JSBridge.h"

Then set up the method you want to call from JS in your view controller.
The method should have a single argument, an NSArray*. For example:

-(void)tappedLink:(NSArray *)params;

Then, in the JS in your web view, do the following:

window.location = "cocoa://tappedLink/param1/param2/param3"

Fill in whatever params you want to send instead of param1 etc. When
that method is called from the JS, your tappedLink method will be called
with all the appropriate params. What’s passed in is the results of
[NSURL pathComponents], which has "/" as the first component, so your
params start at index 1.


This class has been tested back to iOS 6.1.


Setting window.location is the most common way of communicating from JS
into Cocoa. This class implements:

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request

in a reusable way, so you don’t have to edit that method each time you
want to call a new Cocoa method.


This code is released under the MIT License. See the LICENSE file for

Latest podspec

    "name": "UIViewController+JSBridge",
    "version": "1.0.0",
    "summary": "Easy way to communicate between Cocoa code and JavaScript code in a UIWebView.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Josh Justice": "[email protected]"
    "platforms": {
        "ios": "6.0"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "source_files": [
    "requires_arc": false

Pin It on Pinterest

Share This