2

I have AFNetworking setup to monitor the network reachability status, so that when it becomes available I can immediately make a REST call that would have failed while it wasn't.

I've found that it isn't telling me of status changes, however. I'm simulating a 100% loss on my Mac, and during those times, calls to the REST API would fail, but AFNetworking would have its reachability status as availableViewWWAN. Then when I turn off the 100% loss, the REST calls work again, but the status according to AFNetworking hasn't changed.

This is the code I'm using with it right now:

import AFNetworking

class ConnectionManager {
    static let sharedManager = ConnectionManager()
    init() {
        AFNetworkReachabilityManager.sharedManager().startMonitoring()
        AFNetworkReachabilityManager.sharedManager().setReachabilityStatusChangeBlock() {
            (status: AFNetworkReachabilityStatus) -> Void in
            print("reachability status changed: \(status.rawValue)")
        }
    }
}
Andrew
  • 7,693
  • 11
  • 43
  • 81

1 Answers1

3

This is because a 100% loss situation isn't equal to doesn't have a connection at all. 100% loss means that all of the packets are dropped but the network connection still exists, it is usefull when you want to simulate a timeout connection.

In order to simulate the no network case you should turn your wifi connection off on your mac or iDevice, for simulator or physical device.

tx2
  • 724
  • 13
  • 26
  • Unfortunately this only works on a physical device. Disabling wifi on my mac fails to trigger the AFNetworkReachabilityManager status update on the simulator. Does anyone know how to make this work on the simulator? – user3344977 Jan 06 '21 at 18:22