2011-03-08 6 views
1

내 응용 프로그램에서 Reachability v2.0을 사용하고 있습니다.Reachability 2.0 in iPhone

유효한 인터넷 연결을 통해 웹 브라우저에서 Google 페이지를 탐색 할 수 있습니다. 내 앱의 연결 가능성 상태를 테스트하려고 할 때 항상 "호스트에 연결할 수 없습니다"라는 메시지가 표시됩니다.

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

    NSLog(@"host : %@", host); 
    Reachability *hostReach = [Reachability reachabilityWithHostName:host]; 
    if([hostReach currentReachabilityStatus] == NotReachable) { 
     NSLog(@"Host is not Reachable"); 
    } else { 
     NSLog(@"Host is reachable"); 
    } 

위의 코드에서 잘못된 점은 무엇입니까 ??

답변

0

인터넷 연결이 필요한 모든 기능에서이 기능을 구현해보십시오!

#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 
3

reachabilityWithHostname 메서드는 사용자가 정의한대로 URL이 아니라 호스트 이름을 필요로한다는 문제가 있습니다.

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

당신은 같은 호스트를 정의해야