2012-01-18 4 views
-2

서버에있는 xml에서 데이터를 가져 오기 때문에 네트워크가없는 경우 경고보기를 표시하는 방법.iPad에서 네트워크 연결 경고보기

+0

살펴 :

@implementation YourClass Reachability* reachability; @end 

그런 다음 새 도달 가능성 만들고 알림 센터에 관찰자 (자기)를 추가해야합니다 사과의 도달 가능 클래스 –

답변

0

당신의 UIViewController 하위에 "Reachability.h"를 추가하고 해당되는 경우이 코드를 사용합니다.

if (![[Reachability reachabilityForInternetConnection] isReachable]) { 
    [[[[UIAlertView alloc] initWithTitle:@"No Internet connection!" 
           message:@"You have no active internet connection. Please enable wi-fi and re-launch the app." 
           delegate:nil 
         cancelButtonTitle:@"Close" 
         otherButtonTitles:nil, nil] autorelease] show]; 
    return; 
    } 
0

네트워크 가용성을 확인하는 것과 비슷한 문제가있었습니다. Apple의 Reachability 코드는 iOS5 ARC 기능에서 오류를 발생시킵니다.

마지막으로 내가 구현 및 지침은 사이트 자체에서 제공하는 GitHub의 https://github.com/tonymillion/Reachability

그것의 아주 쉽게이 작업 프로젝트를 발견했다.

BR, 하리

1

모두가 말했듯이, 당신은 Reachability.h 및 Reachability.m를 사용해야합니다. 그러나 아무도 알림이있는 올바른 변형에 대해 언급하지 않았습니다.

먼저 변수를 클래스에 추가해야합니다. 그것은 더 나은 .m 파일에 개인 선언합니다 : ...

[[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(showInetConnection) 
                name:kReachabilityChangedNotification 
                object:nil]; 
     reachability = [[Reachability reachabilityForInternetConnection] retain]; 
     [reachability startNotifier]; 

-(void)showInetConnection 
{ 
    if ([reachability currentReachabilityStatus]==NotReachable) { 
     UIAlertView* view = [[UIAlertView alloc] initWithTitle:@"Error" 
                 message:@"There are no inet connection" 
                 delegate:nil 
              cancelButtonTitle:@"Ok" 
              otherButtonTitles:nil]; 
     [view show]; 
     [view release]; 
    } 
}