I have an initial tableviewcontroller which is executing a reachability check. This is working without a problem within the viewDidLoad
, however
How should you use Reachability?
In order to receive notifications, register for the notification, and start the reachability class from Apple:
@implementation AppDelegate {
Reachability *_reachability;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(reachabilityChanged:)
name: kReachabilityChangedNotification
object: nil];
_reachability = [Reachability reachabilityWithHostName: @"www.apple.com"];
[_reachability startNotifier];
// ...
}
@end
To answer the notification:
- (void) reachabilityChanged: (NSNotification *)notification {
Reachability *reach = [notification object];
if( [reach isKindOfClass: [Reachability class]]) {
}
NetworkStatus status = [reach currentReachabilityStatus];
NSLog(@"change to %d", status); // 0=no network, 1=wifi, 2=wan
}
If you rather use blocks instead, use KSReachability.