3

when a UIWebView tries to load a webpage, is there a way to track individual resources like images, js, css being loaded into webview. Basically i am looking for callbacks. Are there callbacks in ios which get fired say when a request for an image is sent out and another callback which is fired when image is downloaded.

1 Answers1

3

If you use NSURLCache you will get callbacks for each file that downloads with the webpage.

Basically you need to subclass the NSURLCache class and set it as shared cache like this :

[NSURLCache setSharedURLCache:cache];

In your subclass you will need to override the - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request method to add your behavior. This will get called for each resource loaded in the webpage.

You can take a look at the Apple Sample code project URL CacheInfo or at the SDURLCache project on github that extend the default NSURLCache behavior.

adig
  • 4,009
  • 1
  • 23
  • 23