我正在尝试在WKWebView控件中加载网页而不将其作为子视图加载:
WKPreferences *preferences = [[WKPreferences alloc] init]; preferences.javaScriptEnabled = YES; WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; configuration.preferences = preferences; WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; webView.navigationDelegate = self; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; [urlRequest setValue:@"Safari" forHTTPHeaderField:@"User-agent"]; [webView loadRequest:urlRequest];
我正在尝试加载的网址是:
https://www.google.com/search?q=mustang
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [webView evaluateJavaScript:@"document.getElementsByTagName('html')[0].outerHTML" completionHandler:^(id result,NSError *error) { NSLog(@"Result %@",result); }]; }
我的NSObject类符合WKNavigationDelegate协议.
我还需要做点什么吗?
非常感谢任何帮助.