Search code examples
iosreachability

Does iOS reachability detect network changes when app is brought to foreground


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?


Solution

  • 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.