NSURLSessionTask never calls back after timeout when using background configuration

后端 未结 5 902
面向向阳花
面向向阳花 2021-02-01 05:35

I am using NSURLSessionDownloadTask with background sessions to achieve all my REST requests. This way I can use the same code without have to think about my applic

5条回答
  •  -上瘾入骨i
    2021-02-01 06:17

    Like you, the app I'm working on always uses a background session. One thing I noticed is that the timeout works properly if it's interrupting a working connection, i.e., the transfer started successfully. However, if I start a download task for a URL that doesn't exist, it wouldn't time out.

    Given that you said your backend had been dead for awhile, this sounds a lot like what you were seeing.

    It's pretty easy to reproduce. Just set a timeout for like 5 seconds. With a valid URL you'll get some progress updates and then see it timeout. Even with a background session. With an invalid URL it just goes quiet as soon as you call resume.

提交回复
热议问题