可以使用或不提供连续检查网络连接

use*_*134 1 reachability ios ios7

我已经在我的项目中实现了可达性,在执行任何网络连接任务时,在某个特定时间检查连接是否可达.但我想要的是连续检查网络是否可以显示通知但如何实现它我不知道所以请帮助

NAN*_*NAV 5

使用此代码检查设备使用可达性是否可用的网络连接

@interface appDelegate : UIResponder <UIApplicationDelegate>
{
    Reachability *internetReachable;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 ........

 internetReachable = [Reachability reachabilityForInternetConnection];
    [internetReachable startNotifier];
 [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(checkNetworkStatus:)
                                                 name:kReachabilityChangedNotification object:nil];
............

}

- (void)checkNetworkStatus:(NSNotification *)notice {
    // called after network status changes

    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
    switch (internetStatus)
    {
        case NotReachable:
        {
            NSLog(@"The internet is down.");
            break;
        }
        case ReachableViaWiFi:
        {
             NSLog(@"The internet is Connected.");
            break;
        }
        case ReachableViaWWAN:
        {
            NSLog(@"The internet is working via WWAN!");
            break;
        }
    }
}

//#import "Reachability.m"

static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
{
#pragma unused (target, flags)
    NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback");
    NSCAssert([(__bridge NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback");

    Reachability* noteObject = (__bridge Reachability *)info;
    // Post a notification to notify the client that the network reachability changed.
    [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
}

it's Solve your problem.
Run Code Online (Sandbox Code Playgroud)