n °
Cependant, vous pouvez swizzle-[NSURLRequest initWithURL:cachePolicy:timeoutInterval:]
pour empêcher la simple requête dès le départ, par exemple:
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);
Notez que le retour nil
n'est pas sûr en général. Il est possible qu'une requête soit stockée dans une structure de données et que le programme plante.