【发布时间】: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) 调用。
【问题讨论】: