When does NSURLSession run?

后端 未结 3 640
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 14:20

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

3条回答
  •  滥情空心
    2021-02-09 15:08

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

    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).

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

    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).

    References:

    URL Loading System Programming Guide

    Foundation Constants Reference

提交回复
热议问题