About Alamofire version for manager use

I am using this code.

var apiPath : String = "/api/list/" let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.timeoutIntervalForRequest = 60 let manager = Alamofire.Manager(configuration: configuration) manager.session.configuration.HTTPAdditionalHeaders = ["_token" : self._token] manager.request(.GET, self._host + self._url + apiPath, parameters: nil) .responseSwiftyJSON ({ (request, response, resultJson, error) in if (resultJson["Success"]) { //get list success } else { println("request : \(request)") println("response : \(response)") println("resultJson : \(resultJson)") println("error : \(error)") } }) 

And I got a problem

Alamofire Version 1.2.1: No Problem

Alamofire versions 1.2.2 and 1.2.3:

 request : { URL: https://test.com/api/list/ } response : nil resultJson : null 

error: Optional (Error Domain = NSURLErrorDomain Code = -999 "canceled" UserInfo = 0x7feb92c434f0 {NSErrorFailingURLKey = https://test.com/api/list/, NSLocalizedDescription = canceled, NSErrorFailingURLStringKey = http s: // / list /})

why the answer was zero and resultJson was empty for versions 1.2.2 and 1.2.3 Please help me, what is the problem in this code ..

+5
source share
2 answers

I just encountered the same problem as you today after upgrading Alamofire from 1.2.1 to 1.2.3.

I found by adding "manager.session.invalidateAndCancel ()" at the end, and inside the responseJSON block this problem was fixed. But what I can’t understand is that how this line of INSIDE code for the responseJSON block affects the responseJSON results.

In any case, I will just work with this fix until the Alamofire team fixes it or someone explains to me why this is happening.

+11
source

I noticed that the API endpoint indicates a secure connection:

HTTP S : //test.com/api/list/

Just try, just in case, maybe this will repeat your situation.

In my case, it was a typo in the API manager code. Which of the parts can be said to be related to application transport security settings.

Just changed the secure protocol from httpS:// to http:// and the error:

Code NSURLErrorDomain = -999 "canceled"

was not and it all worked !

+ And if you had a similar problem. Be sure to discuss this with the support specialist who is setting up the server or API for your application. This means that the server does not have valid security certificates. You may still need a secure connection. Or, this specialist can again configure everything from http:// to httpS:// , and I'm not sure (did not check) whether this will work again when you are already using an insecure http:// connection in the code.

0
source

All Articles