0

I have a class with the delegates for a URLSession. I intend to use it with a background configuration. I understand that the handlers are called when a certain event happens, such as didFinishDownloadingTo.

However, I do have the handle function on my ExtensionDelegate class:

func handle( _ handleBackgroundTasks:
        Set<WKRefreshBackgroundTask>) 
        // Sent when the system needs to launch the application in the background 
        to process tasks. Tasks arrive in a set, so loop through and process each one.
        for task in handleBackgroundTasks {
             switch task {
                     case let urlSessionTask as WKURLSessionRefreshBackgroundTask:

I wonder: where should I handle the data I receive after a download? At the didFinishDownloadingTo or at that function on my ExtensionDelegate class, on the appropriate case of the switch statement?

Another question on the same cycle: I read everywhere that one must remember to setTaskCompleted() after going through the background tasks. But I read elsewhere that one should not set a task as completed if the scheduled data transfer hasn't finished. How do I check that?

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
francisaugusto
  • 1,077
  • 1
  • 12
  • 29

1 Answers1

0

There is a very good explanation here.enter link description here

It worked when I had an array with my WKURLSessionRefreshBackgroundTask. Then, at the end of my didFinishDownloadingTo, I get the task on that array that has the same sessionIdentifier as the current session.configuration.identifier, and set it as complete.

francisaugusto
  • 1,077
  • 1
  • 12
  • 29