Search code examples
iosnetwork-programmingwifireachability

Notifications about network status changes on iOS


I would like my app to get asynchronous notifications about network status changes, i.e. network goes down entirely or when the phone switches from cellular to Wi-Fi.

I know how to test this synchronously using Reachability, but is there a way to get asynchronous notifications?


Solution

  • Assuming you're using Reachability 2.x you can just observe the reachability changed notification:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];