DidFinishNavigation not called

I am trying to load a webpage in a WKWebView control without loading it as a preview:

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]; 

I am trying to download the url:

 https://www.google.com/search?q=mustang 

The following WKNavigationDelegate method WKNavigationDelegate not called:

 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [webView evaluateJavaScript:@"document.getElementsByTagName('html')[0].outerHTML" completionHandler:^(id result, NSError *error) { NSLog(@"Result %@", result); }]; } 

My NSObject class conforms to the WKNavigationDelegate protocol.

Do I need to do something?

Feel any help.

+6
source share
1 answer

Downloading the same URL seems to work for me.

Note: the didFinishNavigation method is called after the main frame is loaded (this includes loading materials from other hosts that are present in the main frame). Therefore, if something responds slowly, the didFinishNavigation method will not be called until resolved.

0
source

Source: https://habr.com/ru/post/976736/


All Articles