0

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.

Hobbit
  • 601
  • 1
  • 9
  • 22
  • Possibly Related: https://stackoverflow.com/questions/23829546/ios-perform-upload-task-while-app-is-in-background – Ahmad F Sep 11 '18 at 06:38
  • Asked for best practice. Moreover, that was related to uploading some stuff. – Hobbit Sep 11 '18 at 07:11
  • Well... if you tried to go for a little reading you would notice that there is "Extending Your App's Background Execution Time" title in the post. I is almost the same in general for the upload and the download. Moreover, you could check: https://developer.apple.com/documentation/foundation/urlsessionconfiguration/1407496-background – Ahmad F Sep 11 '18 at 07:15

1 Answers1

0

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

Mikael
  • 2,355
  • 1
  • 21
  • 45