0

I'm using Apple's Reachability sample code to detect network connectivity changes and wondering how one would get the accurate network status once app has returned to the foreground.

In my current visible UIViewController, I'm registering as an observer for the kReachabilityChangedNotification (same as the Reachability sample code) and also listening for UIApplicationWillEnterForegroundNotification and UIApplicationWillResignActiveNotification events.

In my current visible UIViewController, just before app suspend:

// While the app is in the foreground, I configure SCNetworkReachabilitySetCallback 
// At this point, I have lost connectivity.

[reachability startNotifier];

// this returns NotReachable, as expected
NetworkStatus status = [reachability currentReachabilityStatus];

Now Suspend the app and change wifi settings (change network settings to have a connection)

After app resume: (in the UIApplicationWillEnterForegroundNotification handler)
// this still returns NotReachable even though I now have connectivity.
NetworkStatus status = [reachability currentReachabilityStatus];

Any suggestions on what I'm not doing correctly?

Willam Hill
  • 1,572
  • 1
  • 17
  • 28
  • Take a look at this link, http://stackoverflow.com/questions/4846822/iphone-use-of-background-foreground-methods-in-appdelegate, it talks about app delegate methods and re-entering the foreground. Can you show more of your code. For instance where do you have this in your app? Is it an your app delegate and where so in it? – evan.stoddard Aug 28 '13 at 18:15
  • Clarified my question a bit better. – Willam Hill Aug 28 '13 at 21:41

1 Answers1

0

After app resumes, try this:

//Reachability is the class from Apple's Reachability sample

Reachability *reachability = [Reachability reachabilityForLocalWiFi];

NetworkStatus netStatus = [reachability currentReachabilityStatus];

if (netStatus == NotReachable)
{
    NSLog(@"Not Reachable");
} else
{
    NSLog(@"Reachable");
}
user523234
  • 14,323
  • 10
  • 62
  • 102