2012-01-18 21 views
-2

サーバー上にあるxmlからデータを取得しているためにネットワークがない場合に警告表示を表示する方法。iPadアプリのネットワーク接続警告表示

+0

がに見て...

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

@implementation YourClass Reachability* reachability; @end 

その後、新しい到達可能性を作成し、通知センターにオブザーバー(自己)を追加する必要があります。より良い.mファイルで、それはプライベート宣言されますリンゴの到達可能クラス –

答えて

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を使用する必要があります。 しかし通知の正しいバリアントについて誰も言わなかった:

まず変数をクラスに追加する必要があります。

-(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]; 
    } 
} 
関連する問題