0
我在网上以这种方式使用雨燕下载数据:手柄失去连接
let postEndpoint: String = "http://webisitetest.com"
guard let url = NSURL(string: postEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = NSURLRequest(URL: url)
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)
let task = session.dataTaskWithRequest(urlRequest, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) in
// this is where the completion handler code goes
print(response)
print(error)
})
task.resume()
因为我还可以下载图片和下载可在各种秒内(取决于连接),如果下载过程中用户断开连接,我怎么处理这种情况?
我想向他展示一条消息,例如“连接丢失,下载取消,再试一次”,但我怎么捕获这个事件?
当你说“检查错误”你的意思是这种类型的问题有一个特定类型的错误? – gianni
是的,任何错误都将在完成处理程序中表示为对象。 – Eimantas