gpt4 book ai didi

ios - NSURLSession 后台传输超时未触发

转载 作者:行者123 更新时间:2023-12-01 18:51:17 26 4
gpt4 key购买 nike

当我尝试在网络离线(飞行模式)时启动基本的 NSURLSession 传输时,使用 NSURLSessionConfiguration defaultSessionConfiguration 和 ephemeralSessionConfiguration,我当然会立即收到 NSError :Domain=NSURLErrorDomain Code=-1009 “Internet 连接似乎离线。 “但是使用 NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier,NSURLSession 永远不会返回,没有任何响应,没有触发超时,它会卡住。iOS 8.x 会发生这种情况。使用 iOS 7.x,我得到了预期的 NSError。为什么?有没有办法让一些错误回来?

最佳答案

In general, an NSURLSession background session does not fail a task if something goes wrong on the wire. Rather, it continues looking for a good time to run the request and retries at that time. This continues until the resource timeout expires (that is, the value of the timeoutIntervalForResource property in the NSURLSessionConfiguration object you use to create the session). The current default for that value is one week! In other words, the behaviour of failing for a timeout in iOS7 was incorrect. In the context of a background session, it is more interesting to not fail immediately because of network problems. So since iOS8, NSURLSession task continues even if it encounters timeouts and network loss. It continues however until timeoutIntervalForResource is reached.



所以基本上 timeoutIntervalForRequest 不会在后台 session 中工作,但 timeoutIntervalForResource 会。

我从 developer forum 的一位 Apple 员工那里得到了这个答案。 .此外,我已经通过实现验证了这一点。

关于ios - NSURLSession 后台传输超时未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30872402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com