Created
February 4, 2013 11:57
-
-
Save randomsequence/4706340 to your computer and use it in GitHub Desktop.
UIWebView: Obtaining a return value from - [UIWebView stringByEvaluatingJavaScriptFromString:]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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