[英]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. 然后,需要将文件转储到coredata中以备进一步使用。
What's the best practice for achieving the above functionality? 实现上述功能的最佳实践是什么?
I have downloaded a file using urlSessionDownloadTask, and also dumped it in the coredata. 我已经使用urlSessionDownloadTask下载了一个文件,并将其转储到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 如果您必须在后台触发下载,请使用以下命令: 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. 但是有可能通过连接数据库来使用Core数据的方式与在主应用程序中进行操作的方式相同。 The only big drawback is that you won't be able to get core data context changes when you save your file in Costa. 唯一的大缺点是,将文件保存在Costa中时,您将无法获得核心数据上下文更改。 One way is to use a fetch with a repeat timer on your main app 一种方法是在主应用程序上使用带有重复计时器的访存
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.