NSUrlSession no callback for timeout since iOS 8

Hi,


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?


Thanks,

Accepted Reply

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"

Replies

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"

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

In other words, the bahavoir of failing for a timeout in iOS7 was incorrect.

I think that’s a fair summary.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

This could be accepted in case of there is a connectivity problem to internet, but what if there is a good network connectivity but the URL is not reachable. In this case I experience idle URLSession without any delegation got fired. This is really a big a problem where you can find many people suffer from.

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😉