As far as I know, NSURLProtocl could intercepts all reqeuests sent by URL Loading System. But after testing Alamofire (as well as AFN), My custom NSURLProtocol couldn't intercepts those requests sent by it, whici means the protocol's "canInitWithRequest" won't be consulted, but for those sent by NSURLSession, this method could be invoked.
anyone could help me ?
thx
These tests demonstrate how you could use an NSURLProtocol with Alamofire if you wanted @Yannmm.
Best of luck! 馃嵒
@cnoon锛宨t turns out that if you use a custom NSURLSessionConfiguration (rather than sharedSession()), you are gonna have to do the following to make your NSURLProtocol make difference:
let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
if sessionConfiguration.protocolClasses != nil {
sessionConfiguration.protocolClasses!.insert(KLXFakeDataProtocol.self, atIndex: 0)
}
// use custom sessionConfiguration to initialize your NSURLSession / Alamofire.Manager
this part is neither documented in the NSURLProtocol References nor majority of tutorials on the internet.
Hope may helop someone.
Most helpful comment
@cnoon锛宨t turns out that if you use a custom
NSURLSessionConfiguration(rather thansharedSession()), you are gonna have to do the following to make your NSURLProtocol make difference:this part is neither documented in the NSURLProtocol References nor majority of tutorials on the internet.
Hope may helop someone.