这似乎是xcode登录中的常见输出,但我还没有发现任何与我正在做的事情有关的事情。我已经咨询了YouTube并在这里搜索过去几个小时,但仍然没有找到任何东西。
我试图通过我的应用在数据库中创建一个条目(有效地创建一个用户帐户)。我认为错误源于JSON转换,但我并不完全确定。
这是我的代码的样子:(这是一个嵌套的if-else链,它检查字段之间的有效性,并在点击注册按钮时处于函数中。)
let myURL = URL(string: "http://cgi.soic.indiana.edu/~team12/register.php")
var request = URLRequest(url:myURL!)
request.httpMethod = "POST"
let postString = "username=\(username)&password=\(password)"
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
(data, response, error) in
if error != nil {
print("error=\(error)")
return
}
var err: NSError?
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
if let parseJSON = json {
let resultValue = parseJSON["status"] as! String
print("result: \(resultValue)")
var isUserRegisterd:Bool = false
if (resultValue == "Success") {
isUserRegisterd = true
}
var messageToDisplay:String = parseJSON["message"] as! String
if (!isUserRegisterd) {
messageToDisplay = parseJSON["message"] as! String
}
DispatchQueue.main.async {
let myAlert = UIAlertController(title: "Alert", message:messageToDisplay, preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: .default) {
(action:UIAlertAction) in
self.performSegue(withIdentifier: "registerSuccess", sender: self)
}
myAlert.addAction(OKAction)
self.present(myAlert, animated: true, completion: nil)
}
}
} catch let error as NSError {
err = error
}
}
task.resume()
这是我点击注册按钮时收到的错误,或者我在最后一个字段中按Enter键:
2017-01-05 22:51:25.927582 Freely Market[17933:1522794] [MobileAssetError:29] Unable to copy asset information from https://mesu.apple.com/assets/ for asset type com.apple.MobileAsset.TextInput.SpellChecker
Alert dismissed
2017-01-05 22:51:59.766030 Freely Market[17933:1522809] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-01-05 22:51:59.769789 Freely Market[17933:1522809] [] ____nwlog_simulate_crash_inner_block_invoke dlopen CrashReporterSupport failed
2017-01-05 22:51:59.770043 Freely Market[17933:1522809] [] __nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
2017-01-05 22:51:59.770903 Freely Market[17933:1522809] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
[x86_64] libnetcore-856.30.16
0 libsystem_network.dylib 0x0000000116f58666 __nw_create_backtrace_string + 123
1 libnetwork.dylib 0x0000000117b24006 nw_socket_add_input_handler + 3164
2 libnetwork.dylib 0x0000000117b01555 nw_endpoint_flow_attach_protocols + 3768
3 libnetwork.dylib 0x0000000117b00572 nw_endpoint_flow_setup_socket + 563
4 libnetwork.dylib 0x0000000117aff298 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
5 libnetwork.dylib 0x0000000117b1aae1 nw_endpoint_handler_path_change + 1261
6 libnetwork.dylib 0x0000000117b1a510 nw_endpoint_handler_start + 570
7 libnetwork.dylib 0x0000000117b321f9 nw_endpoint_resolver_start_next_child + 2240
8 libdispatch.dylib 0x0000000116cd5978 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x0000000116cff0cd _dispatch_client_callout + 8
10 libdispatch.dylib 0x0000000116cdce17 _dispatch_queue_serial_drain + 236
11 libdispatch.dylib 0x0000000116cddb4b _dispatch_queue_invoke + 1073
12 libdispatch.dylib 0x0000000116ce0385 _dispatch_root_queue_drain + 720
13 libdispatch.dylib 0x0000000116ce0059 _dispatch_worker_thread3 + 123
14 libsystem_pthread.dylib 0x00000001170a84de _pthread_wqthread + 1129
15 libsystem_pthread.dylib 0x00000001170a6341 start_wqthread + 13
任何帮助都会非常感激,因为我在这里感到茫然。我一直在查看JSON / Swift文档并查看视频/多个站点以找出问题所在,但无济于事。
干杯!