5 Replies
      Latest reply on Oct 29, 2019 2:56 AM by Clay Zhu
      Geoffrey59 Level 1 Level 1 (0 points)



        Since iOS8, the NSUrlSession in background mode does not call this delegate method if the server does not respond.

        -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error

        The download remains idle undefinitely.


        This delegate is called on iOS7 with an error when the server does not respond.


        I have the same problem when I set the device to plane mode during a download. It fails on iOS7 and stays idle whithout failing on iOS8+.


        Do you have insight on this?



        • Re: NSUrlSession no callback for timeout since iOS 8
          eskimo Apple Staff Apple Staff (13,895 points)

          What timeout are you expecting to be obeyed here?

          In general an NSURLSession background session does not fail a task if something goes wrong on the wire.  Rather, it continues looking for a good time to run the request and retries at that time.  This continues until the resource timeout expires (that is, the value in the timeoutIntervalForResource property in the NSURLSessionConfiguration object you use to create the session).  The current default for that value is one week!

          Share and Enjoy

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

            • Re: NSUrlSession no callback for timeout since iOS 8
              Geoffrey59 Level 1 Level 1 (0 points)

              Thanks for the reply.


              In other words, the bahavoir of failing for a timeout in iOS7 was incorrect. In the context of a background session, it is more interesting to not fait immediatly because of network problems. So since iOS8, an NSURLSession task continues even if it encouters timeouts and network loss. It continues however until timeoutIntervalForResource is reached.


              I hope I understood correctly ^^.

              • Re: NSUrlSession no callback for timeout since iOS 8
                Clay Zhu Level 1 Level 1 (0 points)

                Hi, timeoutIntervalForResource property is usually used in background session. Can it be used in normal request? Such as query user info.

                The problem we encountered is that we set timeout interval for a request by NSMutableURLRequest timeoutInterval. As Apple's document described, it specifies the limit between packets. When we analyse our requests logs, some timeout request exceeded the seconds we set to timeoutInterval. We need timeout the requests accurately.

                By reading document and blogs, the timeoutIntervalForResource property seems fit our requirement. Is it appropriate in this situation?

                Looking forword to a reply. Thank you very much