使用Appleのデフォルトの到達可能性クラス:プロジェクト内This link
コピーReachability.hとReachability.mファイルから
ダウンロード到達可能性プロジェクト。
このメソッドをアプリケーションデリゲートファイルに設定します。コードの下に到達可能性の変更通知の使用を取得するための
-(void)initializeRechabilityObeserver
{
//Change the host name here to change the server your monitoring
hostReach = [Reachability reachabilityWithHostName: @"www.apple.com <http://www.apple.com>"];
[hostReach startNotifier];
//[self updateInterfaceWithReachability: hostReach];
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
//[self updateInterfaceWithReachability: internetReach];
wifiReach = [Reachability reachabilityForLocalWiFi] ;
[wifiReach startNotifier];
//[self updateInterfaceWithReachability: wifiReach];
}
:
アプリケーションdidFinishLaunchingにこの通知方法を追加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
internetReachable = [Reachability reachabilityForInternetConnection] ;
[internetReachable startNotifier];
}
も、このメソッドを追加します。
- (void)reachabilityChanged: (NSNotification*)note
{
NSLog(@"Reachability changed");
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
私はあなたがそれが無線LANで作業していないmentioned..Butてきたように同じコードを使用しています有効化されたデバイス – NSS