No matter what I do, willBeginDelayedRequest
is not called. The other delegate calls work perfectly.
Note that this is not even in a background capable app, it’s the simple case …
- run the app
- kill internet connectivity
- now send your api call or whatever
- see message “A”
- later turn on internet
- see message “C”
- 🙁 you will never see message “B”
I’ve seen this behavior in many projects. How to get willBeginDelayedRequest
working??
Delegate …
<code>class Main: UIViewController, CLLocationManagerDelegate, URLSessionTaskDelegate {
</code>
<code>class Main: UIViewController, CLLocationManagerDelegate, URLSessionTaskDelegate {
</code>
class Main: UIViewController, CLLocationManagerDelegate, URLSessionTaskDelegate {
code ..
<code>func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
print("(A) works perfectly - phone was offline when task was started")
}
// Doesn't seem to work ...
func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping (URLSession.DelayedRequestDisposition, URLRequest?) -> Void) {
print("(B) this is never called, even when the command completes perfectly :/")
}
</code>
<code>func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
print("(A) works perfectly - phone was offline when task was started")
}
// Doesn't seem to work ...
func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping (URLSession.DelayedRequestDisposition, URLRequest?) -> Void) {
print("(B) this is never called, even when the command completes perfectly :/")
}
</code>
func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
print("(A) works perfectly - phone was offline when task was started")
}
// Doesn't seem to work ...
func urlSession(_ session: URLSession, task: URLSessionTask, willBeginDelayedRequest request: URLRequest, completionHandler: @escaping (URLSession.DelayedRequestDisposition, URLRequest?) -> Void) {
print("(B) this is never called, even when the command completes perfectly :/")
}
setting the delegate …
<code>let cfg = URLSessionConfiguration.default
cfg.waitsForConnectivity = true
let task = URLSession(configuration: cfg).dataTask(with: request) { [weak self] (data, response, error) in
...
...
print("(C) after net restored, this runs flawlessly")
}
task.delegate = ..
task.resume()
</code>
<code>let cfg = URLSessionConfiguration.default
cfg.waitsForConnectivity = true
let task = URLSession(configuration: cfg).dataTask(with: request) { [weak self] (data, response, error) in
...
...
print("(C) after net restored, this runs flawlessly")
}
task.delegate = ..
task.resume()
</code>
let cfg = URLSessionConfiguration.default
cfg.waitsForConnectivity = true
let task = URLSession(configuration: cfg).dataTask(with: request) { [weak self] (data, response, error) in
...
...
print("(C) after net restored, this runs flawlessly")
}
task.delegate = ..
task.resume()
Recognized by Mobile Development Collective