EDIT: the question was not about what -999 means, but why do I not get an error with the first code fragment, but with the second? Apart of using the Alamofire.Manager in the second code snippet (that should work identical to the Alamofire.request in the first code snippet), everything is identical. Is this a bug, or do I miss something?
I have a function that works with Alamofire.request...
func getMenuFromIsoShortDate(menuDate: String) {
let user = Constants.DummyCredentials.UserName
let password = Constants.DummyCredentials.PassWord
var urlString = ""
let dateForWebservice: NSDate? = NSDate.dateFromIsoString(menuDate)
if let dateForWebservice = dateForWebservice {
urlString = Constants.WebservicePath.DailyMenu + NSDate.dateToIsoSlash(dateForWebservice)
println("urlString: \(urlString)")
}
let credential = NSURLCredential(user: user, password: password, persistence: .ForSession)
Alamofire.request(.GET, urlString)
.authenticate(usingCredential: credential)
.response {
(request, response, data, error) in
if let response = response {
var statusCode = response.statusCode
println("-->statusCode: \(statusCode)")
}
if (error == nil) {
var serializationError: NSError?
let jsonData: AnyObject? = NSJSONSerialization.JSONObjectWithData(data! as! NSData, options: NSJSONReadingOptions.AllowFragments, error: &serializationError)
var parser: Parser = Parser()
let menu: Menu = parser.parseMenuJSON(jsonData)
var dataAccess: DataAccess = DataAccess.sharedInstance
dataAccess.addMenu(menu)
} else {
println("Webservice error: \(error)")
}
}
}
but when I run the code with manager.request - it runs, but gives me a -999 error. Here the altered code:
func getMenuFromIsoShortDate(menuDate: String) {
let user = Constants.DummyCredentials.UserName
let password = Constants.DummyCredentials.PassWord
var urlString = ""
let dateForWebservice: NSDate? = NSDate.dateFromIsoString(menuDate)
if let dateForWebservice = dateForWebservice {
urlString = Constants.WebservicePath.DailyMenu + NSDate.dateToIsoSlash(dateForWebservice)
println("urlString: \(urlString)")
}
let credential = NSURLCredential(user: user, password: password, persistence: .ForSession)
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
manager = Alamofire.Manager(configuration: configuration)
manager.request(.GET, urlString)
.authenticate(usingCredential: credential)
.response {
(request, response, data, error) in
if let response = response {
var statusCode = response.statusCode
println("-->statusCode: \(statusCode)")
}
if (error == nil) {
var serializationError: NSError?
let jsonData: AnyObject? = NSJSONSerialization.JSONObjectWithData(data! as! NSData, options: NSJSONReadingOptions.AllowFragments, error: &serializationError)
var parser: Parser = Parser()
let menu: Menu = parser.parseMenuJSON(jsonData)
var dataAccess: DataAccess = DataAccess.sharedInstance
dataAccess.addMenu(menu)
} else {
println("Webservice error: \(error)")
}
}
}
And here the error message:
Webservice error: Optional(Error Domain=NSURLErrorDomain Code=-999 "Abgebrochen" UserInfo=0x7f8f11c3f210 {NSErrorFailingURLKey=http://test.myserver.de:18507/app/services/mampf/get-menu/2015/05/08, NSLocalizedDescription=Abgebrochen, NSErrorFailingURLStringKey=http://test.myserver.de:18507/app/services/mampf/get-menu/2015/05/08})
What's wrong with this?