iOS background task using NSURLSessionDataTask

柔情痞子 提交于 2019-12-04 20:17:58

You cannot use data tasks for background transfers. Those must be done using download tasks:

Download tasks retrieve data in the form of a file, and support background downloads while the app is not running.

This is explained in Apple's documentation.

Also be sure to check out their background transfer considerations:

With background sessions, because the actual transfer is performed by a separate process and because restarting your app’s process is relatively expensive, a few features are unavailable, resulting in the following limitations...

The key here is that it's running in a separate process which cannot access the data you keep in memory. It must be routed through a file.

I collected a lot of information about background transfer on iOS in a (long) blog post.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!