iPhone reachability checking

From your screen shot, it seems like you do not have Reachability added to your project. You must download Reachability from Apple:

https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html

And add both .h and .m files to your project.

Update: You noted you have Reachability. But looking at the most recent version, I can see why you have the errors you listed – they changed the API and you are probably using sample code you found somewhere else. Try:

in .h file:

//import Reachability class
#import "Reachability.h"

// declare Reachability, you no longer have a singleton but manage instances
Reachability* reachability;

in .m file:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil];

reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

 if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); }

.....

- (void) handleNetworkChange:(NSNotification *)notice
{

  NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

   if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); }
}

Leave a Comment