-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NSURLSession not working (3rd party i.e.:Alamofire neither) #4
Comments
Thanks for the input my friend. 👍 I don't use Alamofire but I will check the issue soon. The library works fine with NSURLSession NFX.sharedInstance().start() let request = NSURLRequest(URL: NSURL(string: "https://www.google.gr")!) let session = NSURLSession.sharedSession() session.dataTaskWithRequest(request) { (data, response, error) -> Void in if error != nil { print("error: \(error)") } else { if ((data) != nil) { print("data: \(data)") } else { print("no data") } } }.resume() I keep this issue open for any further comments :) |
You're right, it works that way but not with the framework. I think it would be important to know why as this is the "default" framework for networking as it was AFNetworking but in Swift (in fact, the author is Matt as well) Please try importing Alamofire and use it like this:
And then wherever:
|
After a little research I found that Alamofire uses NSURLSession internally which does not respect the protocol classes registered using NSURLProtocol.registerClass(). Instead it uses a NSURLSessionConfiguration object which has a protocolClasses property. I think that I must catch Alamofire's case as an exception. I will try some things and I will post a workaround soon. |
You're the man 👍 |
Yeap, but I think to subclass it like this import Alamofire class NFXManager: Alamofire.Manager { static let sharedManager: NFXManager = { let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.protocolClasses?.insert(NFXProtocol.self, atIndex: 0) let manager = NFXManager(configuration: configuration) return manager }() } Then you can use NFXManager.sharedManager instead of Alamofire.Manager. I think your opinion on this, as an Alamofire user is very valuable! So what are you think? :) |
Yep, it's working doing that subclassing. My only doubt is if it will work with some extensions (Reactive, mapping, ...) Alamofire can get pretty big but right now I intend to use it alone. In theory, all should work as it's "the same thing" and we're just overriding the shared manager, but I leave this comment here just in case. I don't like this solution as the best, as I have to create a class for this and inherit, but maybe it's the only way to go with Alamofire. I don't dislike it that much as well :P You can close this issue mate. Keep up the good stuff going! |
It's not catching requests/responses that go through Alamofire ("Equivalent" to AFNetworking in Swift)
Most basic case:
My guessing is that it's not working for any NSURLSession request, this is not working either:
The text was updated successfully, but these errors were encountered: