<commit_before>WebViewJavascriptBridge
=======================

An iOS bridge for sending messages to and from javascript in a UIWebView

Getting started
---------------

Just open the Xcode project (requires Xcode > 4.2) and hit run to see the example application work.

Usage
-----

See ExampleAppDelegate.* for example code. To use it in your own project:

1) Copy `Classes/WebViewJavascriptBridge.h` and `Classes/WebViewJavascriptBridge.m` into your Xcode project

2) Instantiate a UIWebView, a WebViewJavascriptBridge, and set yourself as the bridge's delegate

	#import <UIKit/UIKit.h>
	#import "WebViewJavascriptBridge.h"

	@interface ExampleAppDelegate : UIResponder <UIApplicationDelegate, WebViewJavascriptBridgeDelegate>
	
	@end
	
	@implementation ExampleAppDelegate
	
	- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
	{
	    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
		
		self.webView = [[UIWebView alloc] initWithFrame:self.window.bounds];
	    [self.window addSubview:webView];
	    self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];
	    self.webView.delegate = javascriptBridge;
		
		[self.window makeKeyAndVisible];
		return YES;
	}

	- (void)javascriptBridge:(WebViewJavascriptBridge *)bridge receivedMessage:(NSString *)message fromWebView:(UIWebView *)webView 
	{
	    NSLog(@"MyJavascriptBridgeDelegate received message: %@", message);
	}

	@end

3) Go ahead and send some messages from Objc to javascript

	[self.javascriptBridge sendMessage:@"Well hello there" toWebView:self.webView];

4) Finally, set up the javascript side of things
	
	document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady() {
		WebViewJavascriptBridge.setMessageHandler(function(message) {
			alert('Received message: ' + message)
		})
		WebViewJavascriptBridge.sendMessage('Hello from the javascript')
	}, false)
	<commit_msg>Fix typo in README.<commit_after>WebViewJavascriptBridge
=======================

An iOS bridge for sending messages to and from javascript in a UIWebView

Getting started
---------------

Just open the Xcode project (requires Xcode > 4.2) and hit run to see the example application work.

Usage
-----

See ExampleAppDelegate.* for example code. To use it in your own project:

1) Copy `Classes/WebViewJavascriptBridge.h` and `Classes/WebViewJavascriptBridge.m` into your Xcode project

2) Instantiate a UIWebView, a WebViewJavascriptBridge, and set yourself as the bridge's delegate

	#import <UIKit/UIKit.h>
	#import "WebViewJavascriptBridge.h"

	@interface ExampleAppDelegate : UIResponder <UIApplicationDelegate, WebViewJavascriptBridgeDelegate>
	
	@end
	
	@implementation ExampleAppDelegate
	
	- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
	{
	    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
		
		self.webView = [[UIWebView alloc] initWithFrame:self.window.bounds];
	    [self.window addSubview:webView];
	    self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];
	    self.webView.delegate = self.javascriptBridge;
		
		[self.window makeKeyAndVisible];
		return YES;
	}

	- (void)javascriptBridge:(WebViewJavascriptBridge *)bridge receivedMessage:(NSString *)message fromWebView:(UIWebView *)webView 
	{
	    NSLog(@"MyJavascriptBridgeDelegate received message: %@", message);
	}

	@end

3) Go ahead and send some messages from Objc to javascript

	[self.javascriptBridge sendMessage:@"Well hello there" toWebView:self.webView];

4) Finally, set up the javascript side of things
	
	document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady() {
		WebViewJavascriptBridge.setMessageHandler(function(message) {
			alert('Received message: ' + message)
		})
		WebViewJavascriptBridge.sendMessage('Hello from the javascript')
	}, false)
	
{'fraction_non_alphanumeric': 0.1057668093679174, 'fraction_numerical': 0.0030219088390833542, 'mean_word_length': 5.406451612903226, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7090163', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1064, 'n_words': 309}