Reputation: 4986
I have this code in my app:
-(void)reachAlert:(Reachability*)currentReach {
if(currentReach == hostReach) {
//Make sure we have internet connectivity
//UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle:@"Excellent" message:@"Host Reached" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
//[internetAlert show];
[[SDSyncEngine sharedEngine] startSync];
}
/**
if(currentReach == internetReach) {
//Make sure we have internet connectivity
UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle:@"Good"
message:@"Internet"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[internetAlert show];
}
**/
if(currentReach == wifiReach) {
//Make sure we have internet connectivity
UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle:@"Bad News"
message:@"Only wifi"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[internetAlert show];
}
[TestFlight passCheckpoint:@"reachAlert"];
}
As you can see I commented out internetReach because I figured, whats more important is that we have hostReach. Thus by default we must have internet reach. I also commented out the hostReach alert only because I only want to alert the user in case of NO internet connectivity.
However when testing the app on wifi, i get the bad news only wifi message. Why doesnt it give the hostReach alert?
Upvotes: 0
Views: 295
Reputation: 3447
Reachability is really not ideal for displaying error messages. Ideally you should show an error message when the connection you are trying to use fails, for example NSURLConnection returning a -1009 error.
Upvotes: 1
Reputation: 3541
Don't know if it helps, but I found this somewhere and decided it was a much better solution to the problem -- although someone would likely argue about it:
- (void) verifyInternetConnection
{
NSURL *scriptUrl = [NSURL URLWithString:@"http://youtube.com"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (!data)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet Required" message:@"This device is not currently connected to the Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
alert.tag = 1;
[alert show];
}
}
Upvotes: 0