1

I have an app working just fine on iOS 9 with a Custom NSURLProtocol implemented with NSURLSession. All the requests executed by the client are done with NSURLSession as well and each sessionConfiguration is registering to the protocol before executing the request.

I have an issue with iOS 8 that I don't have with iOS 9. With iOS8 the Custom NSURLProtocol is performing that request non stop, basically an infinite loop of the same request. canInitWithRequest: in the custom protocol gets called way more on iOS 8 than on iOS 9 which basically drives the method startLoading to get called and fire the request after some header modifications that my protocol is supposed to perform.

Is there a known issue with iOS8 where NSURLProtocols and NSURLSession don't behave as expected?

Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
iOSAddicted
  • 389
  • 1
  • 17

1 Answers1

0

I'm not aware of any problems like that, no.

This sounds like your protocol is either:

  • Failing to detect its own header modifications for some reason
  • Failing to make the modifications for some reason
  • Failing to return NO when your protocol is asked if it should handle a request that already contains the modified headers

Be sure that you are using a header field for the purpose of detecting whether to handle the request. There's no guarantee that the specific NSURLRequest object that you pass down into the machinery will come back to you. I'm not even sure I would trust propertyForKey:inRequest:, but that might make me too paranoid.

Critically, don't ever subclass NSURLRequest when working with NSURLSession. In iOS 9, it almost works. The farther back you get, the more broken the behavior, until by iOS 7 you're pretty much relegated to using NSURLConnection. :-)

dgatwood
  • 10,129
  • 1
  • 28
  • 49