djcouchycouch
djcouchycouch

Reputation: 12832

Getting the URL when webViewDidStartLoad is called?

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

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

    // do stuff with urlchar...
}

It's the same code I use in webViewDidFinishLoad and that seems to work. Is that the correct method? Is there a better way? Should I expect to get a valid url when it's called?

Upvotes: 4

Views: 4362

Answers (1)

Evan Mulawski
Evan Mulawski

Reputation: 55334

That is the correct way. The webView argument provided in that delegate method allows you to access the UIWebView that started the request. As a side note, this method is called when images, scripts, and other resources in the page are loaded (once per resource). To make sure the page is completely finished, check the loading property.

Upvotes: 2

Related Questions