Vijay
Vijay

Reputation: 420

Unable to get the response from Reachabilty on very low network

If I am trying to check the reachability of a host which takes too much time for checking and mean while I really want the feedback from reachability to go further what can I do in this. I would like to cancel the reachability check if it takes more that 4 secs and I want to continue my app to work on offline mode. I don't really want my user to wait for sometime until I get the feedback from Reachabiltiy. Is there any work around like if the reachability takes too much time can I skip it in any way?.

- (BOOL)isReachableWithHostName:(NSString *)hostname {
     BOOL reachable;
     Reachability *reachability = [Reachability reachabilityWithHostName:hostname];
     NetworkStatus internetStatus = [reachability currentReachabilityStatus];
     if (internetStatus == NotReachable) {
         reachable = NO;
     } else {
         reachable = YES;
     }

     return reachable;
}

- (BOOL)isGoogleReachable {
    return [self isReachableWithHostName:@"google.com"];
}

What can I do, if I want to take the feedback from reachability if its response time is less than 4 secs.

Upvotes: 0

Views: 75

Answers (1)

maroux
maroux

Reputation: 3824

  1. Use asynchronous methods. Reachability generates notifications when reachability changes.
  2. Add a timeout NSTimer and proceed assuming not reachable after desired time-out.

Upvotes: 1

Related Questions