1 Reply
      Latest reply: Nov 16, 2016 1:50 AM by eskimo RSS
      mharrison Level 1 Level 1 (0 points)

        I'm confused at whether Background Transfer Service is supports for NSURLSessionDataTasks under iOS 8+? The documentation isn't super clear on it.

         

        I also wanted to know - what happens if a SessionTask fails while using Background Transfer Service? I would want to retry the failed request before moving on to the next one in the queue. Has anyone implemented anything similar?

         

        Thank you!

        • Re: SessionDataTask via Background Transfer Service
          eskimo Apple Staff Apple Staff (6,675 points)

          I'm confused at whether Background Transfer Service is supports for NSURLSessionDataTasks under iOS 8+?

          Data tasks are supported in a background session in iOS 8 and later, but there are important caveats.  Specifically, a data task only makes sense if your app is running.  If your app moves to the background and then gets suspended, the data task will fail.  This is a pretty severe limitation, although there’s at least one interesting use case (described below).

          what happens if a SessionTask fails while using Background Transfer Service?

          For download tasks, the system will attempt to retry the download until the timeout expires (specified by the timeoutIntervalForResource property of the configuration you use to create the session).  Upload tasks can’t be retried because they are assumed to not be idempotent.  Once all the tasks in the session are done, your app will be resumed and the state of each task reported to you via delegate callbacks.


          One case where data tasks in a background session are useful relates to requests that might become download tasks.  You can start the request as a data task and then, in -URLSession:dataTask:didReceiveResponse:completionHandler:, look at the response and decide whether you want the request to stay as a data task or become a download task.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"