0

I develop an app and some areas are required to be connected to internet generally. Not important how: 3G,Wifi.

So, my question is do I have to use reachability on the main view or I can implement it only in the specific areas where the internet connection is required?

Thank you in advance.

NCFUSN
  • 1,624
  • 4
  • 28
  • 44

1 Answers1

2

I'm pretty sure it can be implemented wherever you need it.

All you have to do:

  1. Download the classes from here
  2. Add Reachability.h and Reachability.m to your project
  3. Add the SystemConfiguration framework

Then, wherever you want it...

Include it with:

#import "Reachability.h" 

Write a method to call:

-(BOOL)reachable {
    Reachability *r = [Reachability reachabilityWithHostName:@"enbr.co.cc"];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    if(internetStatus == NotReachable) {
        return NO;
    }
    return YES;
}

Call it:

if ([self reachable]) {
    NSLog(@"Reachable");
}
else {
    NSLog(@"Not Reachable");
}
citruspi
  • 6,709
  • 4
  • 27
  • 43