Why is a performance app suitable here?

An example Apple application called Reachability shows how to discover connections. If you have only Wi-Fi, but not the Internet, the application stops for more than a minute on the second line below:

SCNetworkReachabilityFlags reachabilityFlags;
BOOL gotFlags = SCNetworkReachabilityGetFlags(reachabilityRef, &reachabilityFlags);

SCNetworkReachabilityGetFlags comes from SystemConfiguration.framework. Any suggestions on how to get around this?

+5
source share
1 answer

, , , "" SCNetworkReachabilityGetFlags(), (, WiFi ). :

1. , . ReachabilityAppDelegate.m :

// Modified version of existing "updateStatus" method
- (void)updateStatus
{
    // Query the SystemConfiguration framework for the state of the device network connections.
    //self.remoteHostStatus           = [[Reachability sharedReachability] remoteHostStatus];
    self.remoteHostStatus = -1;
    self.internetConnectionStatus   = [[Reachability sharedReachability] internetConnectionStatus];
    self.localWiFiConnectionStatus  = [[Reachability sharedReachability] localWiFiConnectionStatus];
    [tableView reloadData];

    // Check remote host status in a separate thread so that the UI won't hang
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSTimer *timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(updateRemoteHostStatus) userInfo:nil repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    [pool release];
}
// New method
- (void) updateRemoteHostStatus
{
    self.remoteHostStatus = [[Reachability sharedReachability] remoteHostStatus];
    [tableView reloadData];
}

2. API/, . , X , .

:

  • SCNetworkReachabilityGetFlags(), (.. ~ 399 Reachability.m), , www.apple.com "" , " " "" .
  • Apple System Config "" , . , "" , -, , X, , (, ). , SCNetworkReachabilityGetFlags() .
+6

All Articles