Как я могу исправить «Ошибка домена = NSCocoaErrorDomain Code = 3840» Нет значения. «UserInfo = {NSDebugDescription = Нет значения.}»
Когда я запускаю свой код, я получаю эту ошибку, и я не знаю почему.
Ошибка домена = NSCocoaErrorDomain Code = 3840 «Нет значения». UserInfo = {NSDebugDescription = Нет значения.}
Я искал это в интернете, но ничего не нашел.
Это мой код:
let myUrl = NSURL(string: "http://foodhelper.club/registerUser.php");
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "POST";
let postString = "userEmail=\(userEmail!)&userFirstName=\(userFirstName!)&userLastName=\(userLastName!)&userPassword=\(userPassword!)";
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);
NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
dispatch_async(dispatch_get_main_queue())
{
if error != nil {
self.alertMessage(error!.localizedDescription)
print("fail")
return
}
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary
print ("1")
if let parseJSON = json {
let userId = parseJSON["userId"] as? String
print ("2")
if( userId != nil)
{
let myAlert = UIAlertController(title: "Alert", message: "Registration successful", preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default){(action) in
self.navigationController?.popViewControllerAnimated(true) }
myAlert.addAction(okAction);
self.presentViewController(myAlert, animated: true, completion: nil)
} else {
let errorMessage = parseJSON["message"] as? String
print ("3")
if(errorMessage != nil)
{
self.alertMessage(errorMessage!)
}
}
}
} catch{
//email vergleich fehlt, egal ob
print(error)
print("catched error")
let myAlert = UIAlertController(title: "Alert", message: "Registration successful", preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default){(action) in
self.navigationController?.popViewControllerAnimated(true)
}
myAlert.addAction(okAction);
self.presentViewController(myAlert, animated: true, completion: nil)
}
}
}).resume()
}
Спасибо за помощь