Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed some help with Reachability (2.0.3ddg)
    primarykey
    data
    text
    <p>When my app launches, I check for reachability because I need an immediate internet connection. My problem, though, is that it appears there's no immediate confirmation for the <code>NetworkStatus</code>, which means right after the Reachability is setup, I check whether there's a connection, and it returns that there isn't, regardless of whether I am in fact on WiFi/3G, or have turned the radio off.</p> <p>I can confirm that I am in fact getting an Internet connection, because instantly after applicationDidFinishLaunching, there's a notification which then logs "ReachableViaWiFi"..</p> <p>What am I doing wrong? Why is it not confirming a valid Internet connection right away?</p> <pre><code>- (void)applicationDidFinishLaunching:(UIApplication *)application { NetworkStatus netStatus = [hostReach currentReachabilityStatus]; if (netStatus == NotReachable) { ErrorViewController *errorViewController = [[ErrorViewController alloc] initWithNibName:@"ErrorView" bundle:[NSBundle mainBundle]]; [tabBarController.view removeFromSuperview]; [window addSubview:[errorViewController view]]; return; } } -(void)setupReachability { [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil]; hostReach = [[Reachability reachabilityWithHostName:@"www.google.com"] retain]; [hostReach startNotifier]; } -(void)reachabilityChanged:(NSNotification *)notification { Reachability* curReach = [notification object]; NSParameterAssert([curReach isKindOfClass: [Reachability class]]); NetworkStatus netStatus = [curReach currentReachabilityStatus]; BOOL connectionRequired = [curReach connectionRequired]; switch (netStatus) { case NotReachable: { [[NSUserDefaults standardUserDefaults] setInteger:kNOTREACHABLE forKey:kREACHABILITYSTATUS]; NSLog(@"NotReachable"); connectionRequired = NO; break; } case ReachableViaWWAN: { [[NSUserDefaults standardUserDefaults] setInteger:kREACHABLEVIAWWAN forKey:kREACHABILITYSTATUS]; NSLog(@"ReachableViaWWAN"); break; } case ReachableViaWiFi: { [[NSUserDefaults standardUserDefaults] setInteger:kNOTREACHABLE forKey:kREACHABILITYSTATUS]; NSLog(@"ReachableViaWiFi"); break; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload