Reputation: 602
Is there a way with AFNetworking 2 to have the equivalence of
[Reachability reachabilityForLocalWiFi];
Upvotes: 2
Views: 735
Reputation: 602
I looked into Apple reachability code and I think this will do the job.
- (AFNetworkReachabilityManager*) reachabilityForLocalWifi
{
struct sockaddr_in localWifiAddress;
bzero(&localWifiAddress, sizeof(localWifiAddress));
localWifiAddress.sin_len = sizeof(localWifiAddress);
localWifiAddress.sin_family = AF_INET;
// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0.
localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
return [AFNetworkReachabilityManager managerForAddress:&localWifiAddress];
}
Upvotes: 1
Reputation: 3444
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/"];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
NSOperationQueue *operationQueue = manager.operationQueue;
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
[operationQueue setSuspended:NO];
break;
case AFNetworkReachabilityStatusNotReachable:
default:
[operationQueue setSuspended:YES];
break;
}
}];
i am using this in my custom client in some of project , for checking internet reachability. reference afnetworking link
Upvotes: 0