3

I've developed an iOS 7 application. In my application I need to detect if a change in the network connection has occurred (3g \ wifi \ etc). If so, I perform some reconnect with my services.

I couldn't figure out if reachability can detect changes in network connectivity once the app is brought back up to the foreground.

Assume the following scenario:

  1. App launched

  2. User moves app to background, goes on Facebook

  3. App is suspended

  4. User switches from 3g to wifi

  5. User returns to my app

Would reachability detect this connection change?

vondip
  • 13,809
  • 27
  • 100
  • 156
  • It should be, and this sounds like a straightforward scenario to test. Have you tried it? – Steve Madsen Apr 28 '15 at 14:16
  • problem is that I'm not completely sure if me testing it isn't influencing the result (specifically when using the debugger, or even writing to a remote log). Wanted a definite answer – vondip Apr 28 '15 at 14:17
  • Use Rechability classes, in that you can find notifications for almost all such changes. Hope that helps. – Mrunal Apr 28 '15 at 14:18
  • how do you deduce from this sentence that it would update about changes that occurred while app was in background \ suspended ? – vondip Apr 28 '15 at 14:20
  • The debugger doesn't have any impact on the reachability logic. Still, you could write a very simple app that displayed the most recent status on-screen, and then change your network conditions by toggling Wi-Fi and airplane mode from Control Center. Remember that a "definitive answer" here could still be wrong or out of date. – Steve Madsen Apr 28 '15 at 14:28
  • debugger might influence the app's suspension by the OS – vondip Apr 28 '15 at 14:32

3 Answers3

4

Use Rechability classes, in that you can find all such notifications/functionalities. Hope that helps.

Mrunal
  • 13,982
  • 6
  • 52
  • 96
2

I have an app which has to be connected to WiFi and detect when the access point changes or it disconnects on all view controllers which depend on it. I use the Reachability notification mechanism.

For my app, Reachability detects the WiFi changes when I bring the app back into the foreground. So it does do what you want.

I do have to say though that I have not found Reachability to be 100% reliable. The majority of the time it works as you expect, but its not perfect.

As a backup, I check the current network anyway in viewWillAppear on most view controllers. This does not help when an app comes back to the foreground as viewWillAppear is not called as far as I know. You can detect the change in the app delegate though.

Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
0

If I understand you right, you can check the reachability every time your app enters the foreground, some thing like:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
//Check the Reachability here;
}
Summer
  • 488
  • 4
  • 14