In a WWDC conversation this year, an Apple developer on the scene recommended that users never base their access to an application’s Internet applications in an application status. Accessibility example. Often reachability does not provide complete information (it is based on a complex mechanism), and the proposal provided by the engineer is as follows:
- try to connect to the internet no matter what status status is available. then set the user interface hint based on the success / failure result.
- if it crashes due to network problems, then register with Reachability and try again when Reachability gives a green light; this is necessary if you want to automatically recover from a failure state
- in any case, it gives the user the ability to "force retry", whatever the status of "Reach". If it succeeds, reset the user interface prompt.
What the Apple engineer said is completely true: you can often see console error messages in error messages while the Internet connection is completely live.
Other: there is no better “network prompt” than the one displayed on the status bar: if you have a Wi-Fi icon, 3G / 4G icon, the strength of the cellular field.
Returning to the original question: there is no absolute best way to manage this material, it depends a lot on the architecture of the application. If you prefer to configure your network materials in a dedicated class (not a UIViewController, but in a subclass of NSObject), then it makes sense to define a read-only property for this class, which is updated with success / failure after the last Internet connection with the application server (no it makes sense to ping other servers, such as Google or Apple: in the first place, this is not elegant, and in the second place, a problem may arise on your servers serving the application, and not in the status of the device’s Internet connection!).
@property (readonly) BOOL lastConnectionToMyServerSuccess
Then your view controllers can register (by KVO or central notification) so that this property changes and updates its interface accordingly, showing an icon or something else (I repeat: leave the user the opportunity to try manually connecting to the Internet). View controllers must unregister from KVO when hidden from view ("viewWillDisappear:") or unloaded ("viewDidLoad:") or dealloc'd.
Of course, this adds some additional complexity. For example: you are using the application, the internet light was green. Then you pause it, do something else, and after a few minutes return to the application. In this case, the application must ping on its servers in order to restore the status of Internet light again, since after a few minutes the network conditions could change (for example, you are on a train). In any case, all loaded view controllers will receive a KVO notification from the dedicated network class and update themselves.
viggio24 Sep 19 '12 at 8:17 2012-09-19 08:17
source share