I'm using URLSession with background upload. I set session
delegate to self
. I get no delegate methods called when I start upload task with no Internet connection. I want to show message and cancel task if there is no Internet connection or it breaks while uploading. How can you do that?
let session = URLSession(configuration: URLSessionConfiguration.background(withIdentifier: "background"), delegate: self, delegateQueue: nil)
let request = ...
let data = ...
let task = session.uploadTask(with: request, fromFile: dataURL)
task.resume()
When I use not background task I can know it from
let task = self.session.dataTask(with: request) { (data, response, error) in
//if let e = error as NSError?,
// e.code == Int(CFNetworkErrors.cfurlErrorNotConnectedToInternet.rawValue) {
// handle no internet
//}
}