【发布时间】:2016-09-01 17:49:52
【问题描述】:
我正在尝试下载一个文件,我想使用NetworkReachabilityManager 检测它何时失去连接,如下所示:
self.reachabilityManager?.listener = { status in
print("Status: \(status)")
if status == .NotReachable {
self.download?.suspend()
}
else if status == .Reachable(.EthernetOrWiFi) {
self.download?.resume()
}
self.reachabilityManager?.startListening()
一开始我是这样开始下载的:
self.download = self.manager.download(.GET, url) { (temporaryURL, response) -> NSURL in
return NSURL(string: fullFilename)!
}
.progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) in
self.setProgress(totalBytesRead, totalBytesExpectedToRead: totalBytesExpectedToRead)
}
.response { (request, response, data, error) in
self.handleDownloadResponse(fullFilename, response: response, data: data, error: error)
}
当我关闭网络时,我会认为self.download?.suspend() 会暂停下载请求,然后self.download?.resume() 会重新开始下载,但从不调用进度处理程序,并且过了一会儿响应处理程序会启动出现超时错误
我应该采取不同的做法吗?如何实现此行为(恢复网络后继续下载)?
【问题讨论】: