【问题标题】:Background URLSession on watchOS - what is the cycle?watchOS 上的后台 URLSession - 周期是什么?
【发布时间】:2018-01-28 17:32:01
【问题描述】:

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

但是,我的 ExtensionDelegate 类中确实有 handle 函数:

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()。但是我在其他地方读到,如果计划的数据传输尚未完成,则不应将任务设置为已完成。我该如何检查?

【问题讨论】:

    标签: watchkit watchos watchos-4


    【解决方案1】:

    这里有很好的解释enter link description here

    当我的WKURLSessionRefreshBackgroundTask 有一个数组时,它起作用了。然后,在我的didFinishDownloadingTo 的末尾,我得到了与当前session.configuration.identifier 具有相同 sessionIdentifier 的数组上的任务,并将其设置为完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多