Search code examples
iosnsurlprotocol

Why won't startLoading be called in my NSURLProtocol subclass?


I am looking at NSURLProtocol and am trying to insert some headers.

- (void)startLoading {
    NSMutableURLRequest *newRequest = [self.request mutableCopy];
    [NSURLProtocol setProperty:@YES forKey:kAccessCodeProtocolKey inRequest:newRequest];
    self.connection = [NSURLConnection connectionWithRequest:self.request delegate:self];
}

But my startLoading is never called


Solution

  • Have you implemented canInitWithRequest: ? Does it return YES? If not, startLoading will never be called.