虽然苹果禁止了 Flash 禁用了很多广告。我仍然喜欢浏览器的类似广告块的功能。
我注意到 adblock 通过检查所有加载请求的 url 来做到这一点。UIWebview 有可能吗?
任何建议都很好谢谢
不。
但是,您可以调整 -[NSURLRequest initWithURL:cachePolicy:timeoutInterval:]
以防止从一开始就发出请求,例如:
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);
请注意,返回nil
通常是不安全的。请求可能会存储在某些数据结构中,并且程序会崩溃。