AFNetworkReachabilityManager returns Accessible if not available
In my iOS app, I want to monitor the availability of multiple IP addresses on my network.
I tried to create multiple objects AFNetworkReachabilityManager
to monitor these IPs.
So, I create a manager like this:
var server_address = sockaddr_in(
sin_len: __uint8_t(sizeof(sockaddr_in)),
sin_family: sa_family_t(AF_INET),
sin_port: in_port_t(80),
sin_addr: in_addr(s_addr: inet_addr("10.0.0.60")),
sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)
);
item.reachabilityManager = AFNetworkReachabilityManager(forAddress: &server_address);
The object item
has a property reachabilityManager
that stores the manager, rather than ending .
After initializing the manager, I set reachabilityStatusChangeBlock
for the manager as follows, I also started monitoring the manager.
item.reachabilityManager!.setReachabilityStatusChangeBlock({ (status) -> Void in
switch(status) {
case AFNetworkReachabilityStatus.NotReachable, AFNetworkReachabilityStatus.Unknown:
NSLog("UNREACHABLE: \(item.name)");
case AFNetworkReachabilityStatus.ReachableViaWiFi, AFNetworkReachabilityStatus.ReachableViaWWAN:
NSLog("REACHABLE \(item.name)");
}
});
item.reachabilityManager!.startMonitoring();
if i execute reachable
right after startMonitoring()
, it returns false , which i expect .
After that, mine starts reachabilityStatusChangeBlock
and it tells me that IP monitoring is available, while I know for sure that it is not (I am currently not in the same IP range and ping to this IP of course shows that there is no answer on the other end).
If I create an instance AFNetworkReachabilityManager
with an unknown domain name, it returns the status correctly. Therefore, I know that the manager is working correctly.
The only thing I can imagine calling this is a variable sockaddr_in
I am creating to use the dispatcher, perhaps I messed up one of the parameters from the constructor somewhere?
source to share
No one has answered this question yet
Check out similar questions: