简体   繁体   中英

ios: Download large file when app is in background or suspended state

I have got a vendor app. The app needs to download a file containing products data on receiving push notification wether app is in background, suspended or terminated state. Then the file needs to be dumped in coredata for further usage.

What's the best practice for achieving the above functionality?

I have downloaded a file using urlSessionDownloadTask, and also dumped it in the coredata. But that doesn't work when app is in suspended state.

Any help.

If you have to trigger a download in background, use this: https://developer.apple.com/documentation/foundation/url_loading_system/downloading_files_in_the_background

However, because you need to handle notifications with an extension I suppose, you will have a hard time accessing your database from it. It's not recommended. But it's possible by connecting to your database for using Core data the same way you do it in your main app. The only big drawback is that you won't be able to get core data context changes when you save your file in Costa. One way is to use a fetch with a repeat timer on your main app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM