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.

FacebookTwitterDiggStumbleUponGoogle Plus

Original article: Library Enabling Scripting With Javascript Utilizing JavascriptCore With Frameworks And Objects

©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

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