NCFUSN
NCFUSN

Reputation: 1654

Reachability notification. Where's the right place in my app?

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.

Upvotes: 0

Views: 202

Answers (1)

citruspi
citruspi

Reputation: 6891

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");
}

Upvotes: 2

Related Questions