Although apple banned flash which disabled a lot of ad. I still like a adblock like functionality for browser.
I noticed that adblock do so by checking all load request's url. Is that possible with UIWebview?
Any suggestions are well come Thanks
Although apple banned flash which disabled a lot of ad. I still like a adblock like functionality for browser.
I noticed that adblock do so by checking all load request's url. Is that possible with UIWebview?
Any suggestions are well come Thanks
No.
However, you can swizzle -[NSURLRequest initWithURL:cachePolicy:timeoutInterval:]
to prevent the request be issued from the start, e.g.:
static id (*oldMethod)(id self, SEL _cmd, NSURL* theURL, ....);
static id newMethod(id self, SEL _cmd, NSURL* theURL, ....) {
if ([[theURL absoluteString] hasPrefix:@"http://example.com"]) {
[self release];
return nil;
}
return oldMethod(self, _cmd, theURL, cachePolicy, timeoutInterval);
}
....
Method m = class_getInstanceMethod([NSURLRequest class],
@selector(initWithURL:cachePolicy:timeoutInterval:));
oldMethod = method_setImplementation(m, newMethod);
Note that returning nil
is not safe in general. It is possible that a request will be stored in some data structure and the program will crash.