Skip to content

Instantly share code, notes, and snippets.

@iteufel
Created June 10, 2014 23:33
Show Gist options
  • Save iteufel/77e69203f5958593f12a to your computer and use it in GitHub Desktop.
Save iteufel/77e69203f5958593f12a to your computer and use it in GitHub Desktop.
How to extend a WebView with a Custom JSContext
//how to extend a webview with custom Javascript functions
.....
#import <JavaScriptCore/JavaScriptCore.h>
#import <JavaScriptCore/JSBase.h>
.....
_webview.mainFrame.javaScriptContext[@"download"] = ^(NSString *url) {
//do something
};
NSMutableArray *fileList = [[NSMutableArray alloc]init];
[fileList addObject:plugin.settings[@"video.mp4"]];
self.mainFrame.javaScriptContext[@"file"] = fileList;
//now you can access in javascript the file array
//or run the download function
.....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment