NSURLSession何时运行? [英] When does NSURLSession run?

查看:119
本文介绍了NSURLSession何时运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一种情况,当设备收到推送通知时,我会发送 NSURLSession 并结合 NSURLConnection 。我有几个关于 NSURLSession 的问题。

I have a situation in which when the device receives a push notification, I would send a NSURLSession combined with a NSURLConnection. I have a couple of questions regarding NSURLSession.

NSURLSession的如果互联网连接丢失,数据任务会在后台自动恢复吗?

Does NSURLSession's Data Task automatically resume in the background, if internet connection is lost?

NSURLSession 会自动尝试完成如果最初没有互联网的任务,或者会话是否刚刚返回错误?

Does NSURLSession automatically attempt to complete the task if there is no internet initially, or does the session just return with an error?

推荐答案

NSURLSession的数据任务是否会自动恢复在后台,如果互联网连接丢失?

Does NSURLSession's Data Task automatically resume in the background, if internet connection is lost?

如果互联网连接丢失,您将收到错误, NSURLErrorNetworkConnectionLost (错误代码:-1005),在委托方法 URLSession:task:didCompleteWithError 中。您负责使用invalidateAndCancel或finishAndInvalidate重试和/或使会话无效(虽然在网络连接丢失的情况下它已经完成)。

If the internet connection is lost you will receive an error, NSURLErrorNetworkConnectionLost (error code: -1005), in the delegate method URLSession:task:didCompleteWithError. You are responsible for retrying and/or invalidating the session using invalidateAndCancel or finishAndInvalidate (it will have already finished though in the case of a network connect loss).

自动NSURLSession尝试完成任务,如果最初没有互联网,或会话刚刚返回错误?

Does NSURLSession automatically attempt to complete the task if there is no internet initially, or does the session just return with an error?

如果没有互联网连接,您将收到错误, NSURLErrorNotConnectedToInternet (错误代码:-1009),在委托方法 URLSession:task:didCompleteWithError 中。您负责使用invalidateAndCancel或finishAndInvalidate使会话无效(如果需要)(虽然在没有互联网连接的情况下它已经完成)。

If there is no internet connection you will receive an error, NSURLErrorNotConnectedToInternet (error code: -1009), in the delegate method URLSession:task:didCompleteWithError. You are responsible for invalidating the session (if needed) using invalidateAndCancel or finishAndInvalidate (it will have already finished though in the case of no internet connection).

参考文献:

URL加载系统编程指南

Foundation Constants Reference

这篇关于NSURLSession何时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆