【问题标题】:NSURLSession in background didCompleteWithErrorNSURLSession 在后台 didCompleteWithError
【发布时间】:2015-09-12 09:50:21
【问题描述】:

我正在与 NSURLSession 上传和下载作斗争,如果不是因为例如在发送(上传)100 个文件的背景下,一切似乎都可以正常工作:

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error

无论文件是否正确发送,并不总是由系统调用。

More 几乎总是在会话结束时调用 ...

这是正常行为还是我犯了错误......??

我也使用 AFNetworking 进行了一些测试,但我总是得到相同的行为。

谢谢!

【问题讨论】:

标签: ios xcode ios7 ios8


【解决方案1】:

在我的例子中,Swift 3.0 中没有调用委托方法 func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?),因为它仍然依赖于 Objective-C。所以请使用下一个代码作为委托方法:

@objc(URLSession:task:didCompleteWithError:)
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
  //your code here
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多