Skip to content

SCWebViewBridge helps make Javascript calls to Objective-C and Objective-C calls to Javascript easier. Supports passing primitive types as arguments. iOS 5 and above supported.

License

Notifications You must be signed in to change notification settings

sebastiencouture/SCWebViewBridge

Repository files navigation

SCWebViewBridge

SCWebViewBridge helps make Javascript calls to Objective-C and Objective-C calls to Javascript easier. Supports passing primitive types as arguments. iOS 5 and above supported.

Example Usage

Calling Objective-C from Javascript

SCWebViewBridge.call( "methodSimple" );

SCWebViewBridge.call( 
    "methodComplex:array:", 
    new Date(), [ "Stuff, you’ll need to blah blah… view & engagement[ ],", 4.2, true ]  );

Register for calls from Javascript

[self.webViewBridge registerForCalls:self];

Calling Javascript from Objective-C

[self.webViewBridge call:@"testSimple" arguments:nil];

[self.webViewBridge call:@"NamespaceTest.testComplex" arguments:[NSDate date], @"TEST", nil];

Load local HTML file

self.webViewBridge = [[SCWebViewBridge alloc] initWithWebView:self.webView];

[self.webViewBridge loadLocalHtml:@"sample" bundle:[NSBundle mainBundle] error:nil];

Supported Argument Primitive Types

Javascript Objective-C
Number NSNumber
String NSString
Date NSDate
null NSNull
true and false NSNumber
Array NSArray
Object NSDictionary

How to Use

  1. Copy SCWebViewBridge folder into your project
  2. Include SCWebViewBridge.js in HTML/JS
  3. See SCWebViewBridgeDemo/sample.html for example of calling Objective-C from Javascript
  4. See SCWebViewBridgeDemo/ViewController for example of initializing SCWebViewBrdige and calling Javascript from Objective-C

License

SCWebViewBridge, and all the accompanying source code, is released under the MIT license

About

SCWebViewBridge helps make Javascript calls to Objective-C and Objective-C calls to Javascript easier. Supports passing primitive types as arguments. iOS 5 and above supported.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published