Ok, I found a way.
You can create a new class (let's call it MyURLProtocol
) which has NSURLProtocol as subclass. Then add this function to MyURLProtocol
:
+ (BOOL)canInitWithRequest:(NSURLRequest *)request {
NSLog(@"URL = %@", request.URL.absoluteString);
return NO;
}
This function will be called each time your webview makes a request. And then you need to register this protocol with the loading system. In your Appdelegate.m
file include your class and add/replace didFinishLaunchingWithOptions
function with this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NSURLProtocol registerClass:[MyURLProtocol class]];
return YES;
}
All set. Now you can edit canInitWithRequest
function and do what you want with the request.