从 URLSession 返回的位置没有数据(会话:downloadTask:didFinishDownloadingToURL 位置)

No data in location returned from URLSession(session:downloadTask:didFinishDownloadingToURL location)

我正在使用标准后台会话来处理后台提取。操作开始正常并回调:

URLSession(session:downloadTask:didFinishDownloadingToURL location)

被定期调用,但是当我检查位置 url 的内容时,我发现没有。我检查了正在处理的 url,它是好的,当在浏览器上正确提交时 returns 数据。可能是什么?我知道我需要复制数据,因为它在临时缓存中,但当它应该还在时我立即检查了它的内容。这是我的代码:

let span:Float=0.005
func handleRemoteFetch(completionHandler: ((UIBackgroundFetchResult) -> Void)?){
    fetchCompletion=completionHandler;
    fetchInitiation={[unowned self] in
        let theRequest=mapDelegate.sharedMapDelegate().requestForRefreshAndLocation(self.presentLocation!, span:self.span)
        let task = self.backgroundSession.downloadTaskWithRequest(theRequest)
        task.resume()
        print(theRequest.description)
    }
    if (presentLocation != nil){
        fetchInitiation!()
        fetchInitiation=nil
    }
}

func URLSession(session: NSURLSession,
    downloadTask: NSURLSessionDownloadTask,
    didFinishDownloadingToURL location: NSURL){
        print(downloadTask.originalRequest!.description)
        let data = NSData(contentsOfURL: location)
        if data != nil {
            let str = String(data:data!, encoding:NSUTF8StringEncoding)
            print(str);
        } else {
            print("empty output")
        }
}

当应用程序在物理设备上执行时,问题没有出现。一段时间后,它也无缘无故地开始在模拟器上工作。