I was asked something about this but unfortunaitly I did not achieve any thing with answers.
I want to configure session to wait for connectivity, If I turn wifi off, the function when waiting is implemented..
func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
// waiting for connectivity, update UI, etc.
}
This function is implemented successfully when wifi is off, but when I turn back wifi on , task with this session doesn't implemented.
why?
this is my all code:
class AddReserve: UIViewController, URLSessionDelegate,URLSessionTaskDelegate {
private lazy var session: URLSession = {
let configuration = URLSessionConfiguration.default
configuration.waitsForConnectivity = true
return URLSession(configuration: configuration,
delegate: self, delegateQueue: nil)
}()
@IBAction func done(_ sender: Any)
{
let task = session.dataTask(with: URL(string: "https://www.google.com")!)
{ data, response, error in
guard let data = data else
{
return
}
self.postReserve()
}
task.resume()
}
func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
// waiting for connectivity, update UI, etc.
}
}