2017-10-16 11 views
0

私は目的cを初めて導入しました。私は到達可能性テストのようなインターネット接続をチェックするための方法がたくさんあることを知りました.Web Networkingなどを使用していました。目的地cのネットワーク到達可能性をチェックする最良の方法はどれですか

+0

あなたが到達可能性を使用することができます。 –

+0

Reachabilityクラスをダウンロード https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html –

答えて

0

私は常に以下のように到達可能性https://github.com/tonymillion/Reachabilityを使用することを好みます。 GitHubについての説明は、なぜこれを使うべきかについてはっきりしています。>これは、AppleのReachabilityクラスのドロップイン代替であり、ARC互換であり、新しいGCDメソッドを使ってネットワークインターフェースの変更を通知します。

Reachability *internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"]; 

// Internet is reachable 
internetReachableFoo.reachableBlock = ^(Reachability*reach) 
{ 
    // Update the UI on the main thread 
    dispatch_async(dispatch_get_main_queue(), ^{ 

     //do something 
     NSLog(@"REACHABLE!"); 

     } error:^(NSError * _Nullable error) { 
      NSLog(@"Error:%@ ", [error localizedDescription]); 
     }]; 
    }); 
}; 

// Internet is not reachable 
internetReachableFoo.unreachableBlock = ^(Reachability*reach) 
{ 
    // Update the UI on the main thread 
    dispatch_async(dispatch_get_main_queue(), ^{ 

     //do something 
     NSLog(@"UNREACHABLE!"); 

     }); 
}; 

[internetReachableFoo startNotifier]; 

グッドラック:)

関連する問題