Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess requested URL in webViewDidFinishLoad?
    text
    copied!<p>I'm very new to iOS development so please be gentle.</p> <p>I understand that <code>webViewDidFinishLoad</code> will fire for each <code>&lt;iframe&gt;</code> plus the original html page.</p> <p>I'm trying to find the URL of the request that resulted in that <code>webViewDidFinishLoad</code>. As far as I can tell, I can only access webView.request.mainDocumentURL. </p> <p>I find this perplexing. Inside the <code>shouldStartLoadWithRequest</code> method, which fires also for each <code>&lt;iframe&gt;</code> and the original html request, you can access the URL in question, be it the iframe or the parent page.</p> <pre><code>- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSLog(@"Parent page request: %@", request.mainDocumentURL); NSLog(@"Actual URL request: %@", [request URL]); // This returns what I want. return YES; } </code></pre> <p>That first log statement will output the url.</p> <p>However, inside <code>webViewDidFinishLoad</code> </p> <pre><code>- (void)webViewDidFinishLoad:(UIWebView *)webView { NSURLRequest* request = [webView request]; NSLog(@"Parent page request: %@", request.mainDocumentURL); NSLog(@"Request outputs the parent, not the iframe: %@", [request URL]); // how do I access the &lt;iframe&gt; url? } </code></pre> <p>Help me StackOverflow. My google-fu is weak and your wisdom is strong.</p> <p><strong>EDIT:</strong> I should be clear on the goal of this. I want to Do Stuff™ when the load event of the parent page fires, not for iframes. I want this to happen as soon as possible, so I don't want to wait until everything finishes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload