Reputation: 85
I'm working on login in my project and I'm using Alamofire request (swift 2.0) and I always get an error that I can't resolve.
Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo=... {NSErrorFailingURLKey=..., NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=...}
Here is my code:
func login(email: String, password: String, completionHandler: (user: User?, statusCode: Int?, error: NSError?) -> ()) {
let parameters: [String: AnyObject] = [
"email" : email,
"password" : password
]
let urlSuffix = "loginUser"
request(.POST, baseUrl + urlSuffix, parameters: parameters)
.authenticate(user: email, password: password)
.validate()
.responseObject { (request, response, userJSON: Result<User>) in
print(request?.description)
print(response)
print(userJSON.value)
completionHandler(user: userJSON.value, statusCode: response?.statusCode, error: userJSON.error)
}
}
I call that function in my LoginController, when user press a button.
I passed through many posts about that error, but none of them gave me a solution. The problem is, I need the response, a JSON object witch contains user's id. But my Result<User>
is nil due to the error.
Upvotes: 1
Views: 5379
Reputation: 85
Problem resolved, I was passing wrong variables to .authenticate()
They should have been different from my parameters (email, password)
Upvotes: 2
Reputation:
The -999 clue is "cancelled." Your connection isn't permitted. One possible reason is that you're trying to establish an SSL connection but the client does not trust the SSL certificate.
If this is a development system with a self-signed certificate, you'll need to set allowsInvalidSSLCertificate
.
Otherwise, check SSL pinning. It's enabled by default, which means you may need to preload your certificate for the server to be trusted.
Upvotes: 1
Reputation: 3352
Make sure your baseUrl
uses HTTPS protocol or disable App Transport Security for that domain.
Upvotes: 1