Get Updates By E-mail 

Article Written By:
Johann Dowa

Library Enabling Scripting With Javascript Utilizing JavascriptCore With Frameworks And Objects

  •  
  •  
  •  
  •  
  •  

With iOS 7 SDK Apple has provided us with the JavascriptCore framework allowing us to easily utilize the JavascriptCore enginewithin our apps, and here’s an interesting project that aims to make using JavascriptCore easier called JavascriptBridge.

What makes JavascriptBridge interesting is not only that the Javascript is executed through the JavascriptCore engine, but that you can easily access iOS frameworks from within your Objective-C code with little extra code.

Here’s an example from the readme showing how to use JavascriptBridge within an app referencing the MapKit, and MessageUI frameworks:

#import <javascriptbridge /JavaScriptBridge.h>
...

// Retrieve the prepared context
JSContext *context = [JSBScriptingSupport globalContext];

// Add framework support if needed.
// ('Foundation', 'UIKit', 'QuartzCore' enabled by default.)
[context addScriptingSupport:@"MapKit"];
[context addScriptingSupport:@"MessageUI"];

// Evaluate script
[context evaluateScript:
 @"var window = UIWindow.new();"
 @"window.frame = UIScreen.mainScreen().bounds;"
 @"window.backgroundColor = UIColor.whiteColor();"
 @"window.makeKeyAndVisible();"
];

There are also some extra features adding a Node.js style module system, and a syntax for easily definining classes to be used within your Javascript code.

You can find JavascriptBridge on Github here.

A nice actively developed library if you’re looking to do some scripting using Javascript within your apps.

Thanks to Chris for the submission.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments