I need to test for reachability, and the approaches mentioned in this question How to check for an active Internet connection on iOS or OSX? seem appropriate. But my App uses a Tab Bar controller, which in turn deploys multiple View Controllers. Do I need to implement reachability testing in each View Controller, or can I just set it up once in the AppDelegate.m (and then set a CONNECTION_OK flag [for the View Controllers to test] as notification messages came in)? Trying to keep things as simple as possible. Examples welcome.
Asked
Active
Viewed 490 times
2 Answers
0
For me, I use the one from Apple. In particularly these two class methods to check for Internet connectivity or local WiFi availability. I do it right before there is a need to connect to Internet or local WiFi.
// Should be used by applications that do not connect to a particular host
+ (Reachability*) reachabilityForInternetConnection;
//reachabilityForLocalWiFi- checks whether a local wifi connection is available.
+ (Reachability*) reachabilityForLocalWiFi;

user523234
- 14,323
- 10
- 62
- 102
0
What you are thinking of doing is spot-on. You can merely implement the reachability check within your AppDelegate and update a state variable (your CONNECTION_OK flag) that your view controllers can query. This is one of the proper ways to do it (from a programming style perspective).

Stunner
- 12,025
- 12
- 86
- 145