Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect page change in UIWebView and do something before it starts loading?

I need to do something on each page change, before that page starts loading/executing.

First, I tried using -webView:shouldStartLoadWithRequest: but that won't work, because it's also called for XHR requests and iframe requests.

Second, I tried using -webViewDidStartLoad: and comparing webView.request to it's previous value, to see if it changed. This doesn't work, because webView.request is updated only some time after the call.

Any more ideas?

like image 995
Jaka Jančar Avatar asked Jan 15 '10 11:01

Jaka Jančar


2 Answers

The request object in webView:shouldStartLoadWithRequest: has two properties,

BOOL iframe = ![request.URL isEqual:request.mainDocumentURL];

If the URL to load is not equal to the mainDocumentURL you are loading something other than main doc (probably an iFrame).

like image 66
Lee Higgins Avatar answered Nov 13 '22 09:11

Lee Higgins


Have you tried using KVO to observe UIWebView.request?

like image 34
hatfinch Avatar answered Nov 13 '22 08:11

hatfinch