0

虽然苹果禁止了 Flash 禁用了很多广告。我仍然喜欢浏览器的类似广告块的功能。

我注意到 adblock 通过检查所有加载请求的 url 来做到这一点。UIWebview 有可能吗?

任何建议都很好谢谢

4

1 回答 1

1

不。

但是,您可以调整 -[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通常是不安全的。请求可能会存储在某些数据结构中,并且程序会崩溃。

于 2010-08-10T09:42:09.460 回答