Question

Is there a way with AFNetworking 2 to have the equivalence of

[Reachability reachabilityForLocalWiFi];
Was it helpful?

Solution

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];
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top