从Store或TestFlight安装应用程序时,可达性表示无法覆盖

时间:2013-01-25 16:03:08

标签: iphone ios objective-c ipad reachability

我在iOS上的Reachability有这个非常奇怪的问题。如果我在设备上的调试中运行我的应用程序根本没有问题,应用程序运行正常。但是,当我从商店或TestFlight安装它时,即使我使用的是Wi-Fi,我也会收到No Coverage错误,但只有当我尝试执行某些操作时才会出错。如果我不执行该特定操作,应用程序运行正常,直到我这样做。

这是我的代码中涉及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];
  }

}

1 个答案:

答案 0 :(得分: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
 }