Normally, in my iOS Applications that use quite a lot of HTTP requests to communicate with the server, I add an NSBlockOperation to the app's global NSOperationQueue, and then suspend and enable the queue when the application detects a change in internet connection status thus saving any requests currently in the queue until the queue is unsuspended. However, I am not completely sure that in this way, any operations that are currently running will be stopped, and then re-added to the top of the queue.
My question is: are there any better ways to deal with a change in the network status when you are working with HTTP Requests to a remote server i.e. in pausing, resuming, cancelling requests etc...
Internet Connection Types: WiFi, Broadband, DSL, Cable.
You can use the Reachability class to detect when network status changes to avoid sending requests. This is based on, and updated from, some sample code provided by Apple. This will let you know when the internet connection changes without polling.
As far as I know this is the best way to detect network availability. You'll get an instant notification when the network becomes available again. I believe it even tells you what kind of connection is available (WiFi or Cellular).
If the connection drops while making the request, you'll have to handle that condition as you currently are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With