Getting url when calling webViewDidStartLoad?

If I try to get the URL from webView when calling the webViewDidStartLoad method, I get an empty string. Here is my code:

- (void)webViewDidStartLoad:(UIWebView *)webView { NSURL* url = [webView.request URL]; const char* urlchar = [[url absoluteString] UTF8String]; // do stuff with urlchar... } 

This is the same code that I use in webViewDidFinishLoad, and it seems to work. Is this the correct method? Is there a better way? Should I expect to get a valid URL when it is called?

+4
source share
1 answer

This is the right way. The webView argument provided in this delegate method allows you to access the UIWebView that launched the request. As a side note, this method is called when loading images, scripts, and other resources on a page (once per resource). To ensure that the page is complete, check the loading property.

+2
source

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


All Articles