Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 18035

Cannot get URLSessionTaskDelegate#willBeginDelayedRequest to be called, regardless

$
0
0

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 ...

class Main: UIViewController, CLLocationManagerDelegate, URLSessionTaskDelegate {

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 ...

let cfg = URLSessionConfiguration.defaultcfg.waitsForConnectivity = truelet 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()

Viewing all articles
Browse latest Browse all 18035

Trending Articles