iPhone reachability checking
Solution 1:
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"); }
}
Solution 2:
[reachability setHostName:@"http://www.google.com"];
Attention! I encountered the problem that it's always "NotReachable" if the http:// prefix is used.
Raphael
Solution 3:
Here's the right code as it works for me today!!!
[[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"); }