I'm having this really weird issue with Reachability on iOS. If I run my app in debug on a device there's no problem at all, the app runs fine. But when I install it from the store or from TestFlight I get my No Coverage error even if I'm on Wi-Fi, but only when I try to do certain actions. If I don't do that specific action the app runs fine until I do.
This is the part of my code that deals with Reachability:
- (void)connectionReachabilityChanged:(NSNotification *)notice {
NetworkStatus status = [self.connectionReachability currentReachabilityStatus];
if (status == NotReachable) {
self.inCoverage = NO;
} else {
self.inCoverage = YES;
}
}
- (void)hostReachabilityChanged:(NSNotification *)notice {
NetworkStatus status = [self.hostReachability currentReachabilityStatus];
if (status == NotReachable) {
self.inCoverage = NO;
} else {
self.inCoverage = YES;
}
}
- (void)displayAlertOfType:(AlertType)type {
if (type == AlertTypeNoCoverage) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"No coverage"
message: @"You current have no data coverage, try again later"
delegate: self
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
}
if (type == AlertTypeOperationNotCompleted) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops... Something went wrong"
message:@"The operation couldn't be completed, try again later"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
Reachability *reachability = [Reachability sharedReachability];
[reachability setHostName:@"http://www.google.com/"];
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];
if(remoteHostStatus == NotReachable) {
//no internet connection
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"No coverage"
message: @"You current have no data coverage, try again later"
delegate: self
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
}
else if (remoteHostStatus == ReachableViaWiFiNetwork) {
//wifi connection found
}
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) {
//EDGE or 3G connection found
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.