0
我使用的可達性類監測一對夫婦iPhone應用程序的網絡連接和服務器可用性的網絡連接。我在我的AppDelegate下面的代碼:有道檢查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];
當我使用配置文件的工具軟件之一(一個專門的博客的讀者對我的企業博客),我看到了一個網絡流量+5.9 MB的差異當我打開通知程序時,與評論這些行。
什麼是檢查向服務器發送請求之前的網絡連接的正確方法?我可能不應該全天監控連接,但只有當我需要知道時。
我的其他應用程序與Web服務API通信發佈的網頁和視頻,我想知道有沒有嘗試發佈之前,該服務的連接,但我想,我可以最大限度地減少網絡流量。
我猜,這是一件事蘋果看起來批准/在App Store拒絕的應用程序時。
我剛剛使用了本文[SO] [1]中提出的技術。 [1]:http://stackoverflow.com/questions/7015644/ios-reachability-not-recognizing-when-host-is-removed/7016594#comment9733939_7016594 – user523234
嘗試使用AFNetworking它有一個內置的支持檢測服務器狀態,並使用塊做到這一點...檢查出來! – ahmad