【问题标题】:URLSessionTask runs always into an errorURLSessionTask 运行时总是出错
【发布时间】:2017-01-16 08:29:47
【问题描述】:

在我的 ExtensionDelegate 中,我使用以下代码启动 URLSessionTask:

func scheduleNextURLSessionTask() {
    let backgroundConfigObject = URLSessionConfiguration.background(withIdentifier: "myIdentifier")

    let backgroundSession = URLSession(configuration: backgroundConfigObject, delegate: self, delegateQueue: nil)
    let retrieveTask = backgroundSession.dataTask(with: URL(string: "https://api.wedtec.net/cryptocoins/index.php?bitcoin&simple")!)
    retrieveTask.resume()
}

当然,我的 ExtensionDelegate 实现了 URLSessionDataDelegate。 这总是会出错。意味着

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)

将触发以下错误消息:

URLSessionTask didCompleteWithError Optional(Error Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service" UserInfo={NSErrorFailingURLKey=https://api.wedtec.net/cryptocoins/index.php?bitcoin&simple, NSErrorFailingURLStringKey=https://api.wedtec.net/cryptocoins/index.php?bitcoin&simple, NSLocalizedDescription=Lost connection to background transfer service})

知道这里有什么问题吗? scheduleNextURLSessionTask 从后台进程 (WKApplicationRefreshBackgroundTask) 调用。

【问题讨论】:

    标签: xcode swift3 watchos-3


    【解决方案1】:

    根据 Apple 文档,只有下载和上传任务可以安排为后台任务执行:

    “仅支持上传和下载任务(不支持数据任务)。”

    检查here,在“后台传输注意事项”下-

    【讨论】:

      猜你喜欢
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 2019-06-11
      • 1970-01-01
      • 2014-07-08
      • 2021-12-23
      • 1970-01-01
      • 2015-02-22
      相关资源
      最近更新 更多