3

In my ExtensionDelegate I'm starting a URLSessionTask with following code:

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()
}

My ExtensionDelegate implements URLSessionDataDelegate, of course. This runs always into an error. Means

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

Will be triggered will following error message:

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})

Any Idea what could be wrong here? scheduleNextURLSessionTask is called from a background process (WKApplicationRefreshBackgroundTask).

4

1 回答 1

0

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

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

在“后台传输注意事项”下检查此处-

于 2017-03-29T08:01:04.390 回答