Objective c iPhone中的可达性2.0

Objective c iPhone中的可达性2.0,objective-c,uikit,reachability,Objective C,Uikit,Reachability,我正在我的应用程序中使用可达性v2.0 我有一个有效的互联网连接,能够在网络浏览器中浏览谷歌网页。 当我尝试在我的应用程序中测试可达性状态时,它总是显示“主机不可达” 上面的代码有什么错误???请尝试在任何需要internet连接的功能上实现此功能 #import "testConnectionViewController.h" #import "Reachability.h" @implementation testConnectionViewController - (void)d

我正在我的应用程序中使用可达性v2.0

我有一个有效的互联网连接,能够在网络浏览器中浏览谷歌网页。 当我尝试在我的应用程序中测试可达性状态时,它总是显示“主机不可达”


上面的代码有什么错误???

请尝试在任何需要internet连接的功能上实现此功能

#import "testConnectionViewController.h"
#import "Reachability.h"

@implementation testConnectionViewController




- (void)doWeHasInternets{

  UIAlertView *errorView;
  Reachability *r = [Reachability reachabilityWithHostName:@"m.google.com"];
  NetworkStatus theInternets = [r currentReachabilityStatus];


  if(theInternets == NotReachable) {
    errorView = [[UIAlertView alloc]
                 initWithTitle: @"Network Error"
                 message: @"The internets are down, everyone run for your lives!"
                 delegate: self
                 cancelButtonTitle: @"Nooooooo!" otherButtonTitles: nil];    
  }
  else
  {
    errorView = [[UIAlertView alloc]
                 initWithTitle: @"Whew!"
                 message: @"Relax, the internets are here."
                 delegate: self
                 cancelButtonTitle: @"Yay!" otherButtonTitles: nil];    
  }

  [errorView show];
  [errorView autorelease];
}

@end

问题是reachabilityWithHostname方法需要的是主机名,而不是您定义的URL

您需要将主机定义为:-

NSString *host = @"www.google.co.in";
NSString *host = @"www.google.co.in";