Skip to content

Instantly share code, notes, and snippets.

@derMani
Forked from irace/BIWebViewDelegate.m
Created January 21, 2014 14:07
Show Gist options
  • Save derMani/8540723 to your computer and use it in GitHub Desktop.
Save derMani/8540723 to your computer and use it in GitHub Desktop.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *urlString = [[request URL] absoluteString];
if ([urlString hasPrefix:@"js:"]) {
NSString *jsonString = [[[urlString componentsSeparatedByString:@"js:"] lastObject]
stringByReplacingPercentEscapes];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
id parameters = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers
error:&error];
if (!error) {
// TODO: Logic based on parameters
}
}
return NO;
}
var sendObjectMessage = function(parameters) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', 'js:' + JSON.stringify(parameters));
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
};
sendObjectMessage({name: 'Bryan', company: 'Tumblr'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment