Reachability
is a network helper utility class, its used to get various informations about the connection status
What is the main purposes of Reachability?
Reachability is used to query the network status, and to register your listeners to get informed when connectivity changes.
Is this the main purpose of Reachability, to show the user a message?
No, its main usage is to test if there is Internet connectivity, or to get notified if the connectivity changes
For example if NSURLConnection
request has failed do I need to use
Reachability somehow to resend the request?
Yes, you could use it. For example, what I normally do in my project is to save all the requests that have been made to a remote server.
Let's say I want to download 10 files. When any file fails the download process due to no Internet connection, I save them to an array of failed downloads.
Then, when Reachability informs me that the Internet connection has been restored, I iterate through this array and start the download process again.
What is the proper use of Reachability?
It depends, on your patterns and needs.
Is it common to use only one instance when app launch, and then listen
to network changes?
Yes, that is what I do. In my projects, I only have 1 instance of a download manager class, and this class has the only alive instance of Reachability.
Or should I check myself the reachability status before every network
request?
You can do that without having multiple instance of Reachability classes. What I normally do is to have a method inside my download manager that tells me using Reachability if there is connection or not.
Is it enough to use reachabilityWithHostName
or do I need also
reachabilityForLocalWiFi
and reachabilityForInternetConnection
?
I'm not sure about this one, but what I normally do is to test connectivity on all the means. I don't differentiate between 3G or WiFi, but there are some implementations where this info (WiFi or 3G) could be useful.