Skip to content

Instantly share code, notes, and snippets.

@randomsequence
Created February 4, 2013 11:57
Show Gist options
  • Save randomsequence/4706340 to your computer and use it in GitHub Desktop.
Save randomsequence/4706340 to your computer and use it in GitHub Desktop.
UIWebView: Obtaining a return value from - [UIWebView stringByEvaluatingJavaScriptFromString:]
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 480.0)];
webView.delegate = self;
[webView loadHTMLString:@"<html></html>" baseURL:[[NSBundle mainBundle] bundleURL]];
#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *script = @"(function(){return 'Hi, how are you?';})();";
NSString *returnValue = [webView stringByEvaluatingJavaScriptFromString:script];
NSLog(returnValue); // Hi, how are you?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment