【发布时间】:2016-08-20 22:40:00
【问题描述】:
当我运行我的代码时,我得到了这个错误,我不知道为什么。
错误域=NSCocoaErrorDomain 代码=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()
}
感谢您的帮助
【问题讨论】:
-
这不是和this一样吗?
-
不,这是一个普遍的问题,并不像我的其他问题那样具体,所以我希望我能在这里得到答复。 @OOPer
-
那么你认为你的另一个问题应该是什么?您认为这两个问题都需要作为独立问题存在?
-
但现在我得到了答案,所以对我来说没问题:)
-
好的,那么,请努力为您的第一个问题找到答案。