如果我没有使用后台配置,这种情况经常发生,但如果我进行这样的配置,我的回调/委托方法永远不会被调用.当我再次激活wifi时,它最终会被调用.
我希望马上收到一个错误.我错过了什么吗?
解决方法
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 in the
timeoutIntervalForResource property in the NSURLSessionConfiguration
object you use to create the session). The current default for that
value is one week!
我在developer forum找到了上述答案.
可能有助于后台会话的更多细节:
Another benefit is that in a background session,we monitor the
network and power environment for you. This means that we cover things
like network reachability and connectivity for you,so you don’t have
to use the reachability APIs at all. We won’t attempt to establish a
connection until we know that the server is reachable. And similarly,
if the user is performing a download and steps out of Wi-Fi,normally
that task would then fail with a transmission error. But,in a
background session,we’ll actually recover from that automatically and
retry it and resume where we left off if the download is resumable.
And you won’t hear about that error.
资料来源:WWDC 2014