I implemented the Reachability class but to my knowledge that only detects if the internet is "reachable". Here is the class:
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
I want to know before someone clicks on a link (for example) in the app if the internet is working. By working I mean it will actually load. Not if it is just reachable.
With the Reachability class, if I turn off wifi on my phone, the following method will still return true:
This is because under Cellular settings I have "Enable 3G" set to on. However my phone plan cannot get internet unless on wifi. When "Enable 3G" is set to on, the above method turns true (because technically WWAN is reachable). When it is turned off (as well as wifi turned off), the method will return false. However I can't expect an app user to know to turn off "Enable 3G" so this method is pretty useless for determining if they can actually connect to the internet or not.
I have also tried the following method:
However I don't think it works all that well because sometimes if a website is cached it will return true even when there is no internet connection.
The bottom line is how can I detect if internet is working on a phone? Not just if it is reachable (which is what the Reachability class determines).
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
I want to know before someone clicks on a link (for example) in the app if the internet is working. By working I mean it will actually load. Not if it is just reachable.
With the Reachability class, if I turn off wifi on my phone, the following method will still return true:
Code:
-(bool)canReachInternet
{
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable)
return false;
else
return true;
}
This is because under Cellular settings I have "Enable 3G" set to on. However my phone plan cannot get internet unless on wifi. When "Enable 3G" is set to on, the above method turns true (because technically WWAN is reachable). When it is turned off (as well as wifi turned off), the method will return false. However I can't expect an app user to know to turn off "Enable 3G" so this method is pretty useless for determining if they can actually connect to the internet or not.
I have also tried the following method:
Code:
- (BOOL)isNetworkAvailable
{
char *hostname;
struct hostent *hostinfo;
hostname = "microsoft.com";
hostinfo = gethostbyname(hostname);
if (hostinfo == NULL)
return false;
else
return YES;
}
However I don't think it works all that well because sometimes if a website is cached it will return true even when there is no internet connection.
The bottom line is how can I detect if internet is working on a phone? Not just if it is reachable (which is what the Reachability class determines).















