AFNetworking IP Availability in Fast - Always Consistent with General Reachability?

I need help to understand why I see the following.

AFNetworking 3.0.4 on iOS9.x

If I grab the reachability manager with

 AFNetworkReachabilityManager.sharedManager() 

and then add setReachabilityStatusChangeBlock, then I get exactly what I expect.

  • Flight Mode: NotReachable
  • WiFi off: ReachableViaWWAN
  • Wi-Fi ReachableViaWiFi : ReachableViaWiFi

So, in general, everything works as expected.

But I would like to be more precise - we know which IP address we are talking to, so I would like to use managerForAddress . Here is the code that I downloaded with the load from the network (most of the examples there are not fast for obj-c) - in the following - ip is the address bar (square square shape):

 let isLittleEndian = Int(OSHostByteOrder()) == OSLittleEndian let htons = isLittleEndian ? _OSSwapInt16 : { $0 } var address = sockaddr_in() address.sin_len = UInt8(sizeofValue(address)) address.sin_family = sa_family_t(AF_INET) address.sin_port = htons(443); address.sin_addr.s_addr = inet_addr(ip); addressReachability = withUnsafePointer(&address) { AFNetworkReachabilityManager(forAddress: UnsafePointer($0)) } 

Then I can add setReachabilityStatusChangeBlock to this manager and start monitoring.

Now - it doesnโ€™t matter what I send as IP - an empty string, a valid IP address where 443 is listening, a valid IP address where 443 is not listening, an invalid IP address - the results correspond exactly to that from sharedManager - if Iโ€™m on wifi - then itโ€™s ReachableViaWiFi , if I'm only on 4G, then itโ€™s ReachableViaWWAN , if I'm on an airplane, it's NotReachable .

So, either I completely misunderstood how managerForAddress used, or I have a code error :) In any case, I would like to hear that I misunderstood / did not understand.

+5
source share

Source: https://habr.com/ru/post/1242769/


All Articles