NSURLProtocol вам в помощь,
eng.42go.com/customizing-uiwebview-requests-with-n... видит все http запросы.
Например моя заготовка для детекта mp3, чтобы зарегать класс, выполняю. этот код
[NSURLProtocol registerClass:[MP3DetectURLProtocol class]];
MP3DetectURLProtocol.h
#import <Foundation/Foundation.h>
@interface MP3DetectURLProtocol : NSURLProtocol
@property (nonatomic, strong) NSURLConnection *connection;
@end
MP3DetectURLProtocol.m
#import "MP3DetectURLProtocol.h"
@implementation MP3DetectURLProtocol
static NSString *PBProxyURLHeader = @"X-PB";
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
//if([[request.URL absoluteString] rangeOfString:@"mp3"].length !=0)
NSLog(@"request url = %@", [request.URL absoluteString]);
if ([request valueForHTTPHeaderField:PBProxyURLHeader] == nil)
{
return YES;
}
return NO;
}
+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request
{
return request;
}
- (void) startLoading
{
NSMutableURLRequest *newRequest = [self.request mutableCopy];
[newRequest setValue:@"" forHTTPHeaderField:PBProxyURLHeader];
// Here we set the User Agent
//[newRequest setValue:@"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36 Kifi/1.0f" forHTTPHeaderField:@"User-Agent"];
//[NSURLProtocol setProperty:@YES forKey:@"UserAgentSet" inRequest:newRequest];
//NSLog(@"start loading");
self.connection = [NSURLConnection connectionWithRequest:newRequest delegate:self];
}
- (void)stopLoading
{
//[self.connection cancel];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.client URLProtocol:self didLoadData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[self.client URLProtocol:self didFailWithError:error];
self.connection = nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageAllowed];
}
- (NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)response
{
[self.client URLProtocol:self wasRedirectedToRequest:request redirectResponse:response];
return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self.client URLProtocolDidFinishLoading:self];
self.connection = nil;
}
@end