0

我在 iOS 上遇到了这个非常奇怪的可达性问题。如果我在设备上以调试方式运行我的应用程序,则完全没有问题,该应用程序运行良好。但是当我从商店或从 TestFlight 安装它时,即使我在 Wi-Fi 上,我也会收到无覆盖错误,但只有当我尝试执行某些操作时。如果我不执行该特定操作,则应用程序运行良好,直到我执行为止。

这是我处理可达性的代码部分:

- (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];
  }

}
4

1 回答 1

0
 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
 }
于 2013-01-25T21:50:45.913 回答