0

我有一个带有 URLSession 代表的课程。我打算将它与后台配置一起使用。我知道当某个事件发生时会调用处理程序,例如didFinishDownloadingTo.

但是,我的handleExtensionDelegate 类确实具有该功能:

func handle( _ handleBackgroundTasks:
        Set<WKRefreshBackgroundTask>) 
        // Sent when the system needs to launch the application in the background 
        to process tasks. Tasks arrive in a set, so loop through and process each one.
        for task in handleBackgroundTasks {
             switch task {
                     case let urlSessionTask as WKURLSessionRefreshBackgroundTask:

我想知道:我应该在哪里处理下载后收到的数据?在didFinishDownloadingTo我的 ExtensionDelegate 类的那个或那个函数上,在 switch 语句的适当情况下?

setTaskCompleted()同一周期的另一个问题:在完成后台任务后,我到处阅读必须记住的内容。但是我在其他地方读到,如果计划的数据传输尚未完成,则不应将任务设置为已完成。我该如何检查?

4

1 回答 1

0

这里有一个很好的解释。在此处输入链接描述

当我的WKURLSessionRefreshBackgroundTask. 然后,在 my 结束时didFinishDownloadingTo,我在该数组上获得与 current 具有相同 sessionIdentifier 的任务session.configuration.identifier,并将其设置为完成。

于 2018-02-04T18:23:45.233 回答