在我的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可选(错误域= NSURLErrorDomain代码= -997"丢失与后台传输服务的连接" UserInfo = {NSErrorFailingURLKey = https://api.wedtec.net/cryptocoins/index.php?bitcoin&simple,NSErrorFailingURLStringKey = https://api.wedtec.net/cryptocoins/index.php?bitcoin&simple,NSLocalizedDescription = Lost连接到后台传输服务})
任何想法在这里可能出错? scheduleNextURLSessionTask是从后台进程调用的(WKApplicationRefreshBackgroundTask)。