私はReachabilityクラスを使用して、いくつかのiPhoneアプリでネットワーク接続とサーバーの可用性を監視しています。iOSのネットワーク接続を確認する適切な方法
// Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the
// method "reachabilityChanged" will be called.
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
// Start checking for reachability to myWebService.com
//Change the host name here to change the server your monitoring
hostReach = [Reachability reachabilityWithHostName: @"myWebService.com"];
[hostReach startNotifier];
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
wifiReach = [Reachability reachabilityForLocalWiFi];
[wifiReach startNotifier];
私は楽器を使ったアプリの一つ(私の会社のブログのための専用のブログの読者を)プロファイル、私は1つ上のネットワークトラフィックの5.9 Mbのの違いを参照してください。私は私のAppDelegateに次のコードを持っています私がノーティファイアをオンにすると、その行をコメントアウトしています。
サーバにリクエストを送信する前にネットワーク接続を確認する適切な方法は何ですか?私はおそらく接続をフルタイムで監視してはいけませんが、私が知る必要があるときだけです。
私の他のアプリはWebサービスAPIと通信してページやビデオを投稿していますが、投稿する前にそのサービスに接続しているかどうかを知りたいのですが、できる限りネットワークトラフィックを最小限に抑えたい。
これは、Appleがアプリストアでアプリを承認/却下しているときに、Appleが探していることだと思います。
私はこの[SO] [1]で提案された手法を使用しました。 [1]:http://stackoverflow.com/questions/7015644/ios-reachability-not-recognizing-when-host-is-removed/7016594#comment9733939_7016594 – user523234
それが組み込まれていAFNetworking使用してみてくださいサーバーのステータスを検出するためのサポートとブロックを使用して...チェックアウト! – ahmad