How to Intercept UIWebView URL Resource Requests

It was very difficult to understand, but I think I understood it successfully. This code can be useful if you are trying to build a progress indicator, for example, or do something at some point in the page load life cycle.

With this code, you can see every download URL, be it an image, a css file, etc.

@interface CustomURLProtocol : NSURLProtocol @end @implementation CustomURLProtocol + (void)enable { [NSURLProtocol registerClass:[CustomURLProtocol class]]; } + (BOOL)canInitWithRequest:(NSURLRequest *)request { // Do something here with request.URL.absolutestring return NO; } @end 

Now just call [CustomURLProtocol enable].

+4
source share

All Articles