I have a NSURLSession that runs in a background queue. I'm adding my NSURLProtocol
subclass to the NSURLsessionConfiguration.protocolClases
but the override class func canInitWithRequest(request: NSURLRequest) -> Bool
never gets called.
This is how I'm adding my NSURLProtocol
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.protocolClasses!.append(MockNetwork)
urlSession = NSURLSession(configuration: configuration, delegate: self, delegateQueue: operationQueue)
Also I tried with the session not running on background doing but also didn't work:
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.protocolClasses!.append(MockNetwork)
urlSession = NSURLSession(configuration: configuration)
As this was not working I just tried:
urlSession = NSURLSession.sharedSession()
And calling this in my AppDelegate
NSURLProtocol.registerClass(MockNetwork)
This does work, what am I doing wrong?!