Friday, 8 November 2013

Reachability Class For iOS

Hello Friends,

                      I have attached Reachability Class to check the network. This class can check either your internet connection is available or not . You can download the SDK of Reachability Class from here  :-

 https://github.com/preetlotey999/Reachability-Class-For-iOS.git


After download you can drag & drop this SDK to your project & make sure you tick the following things show in the screen shot :-



Import Reachability Class in your class then write this code in your viewDidLoad method :-

- (void) viewDidLoad
{
    [super viewDidLoad];

    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    
    NetworkStatus internetStatus = [reachability currentReachabilityStatus];
    
    if (internetStatus != NotReachable)

    {
                // Write your code here.
    }

    else
     {
              UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reachability" message:@"Please check your internet connection." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        
        [alert show];
     }
}

Below is the screen shot :-



For arc enabled project do this :-



Thanks Guys. If you like the code then post a comment & if you have any query regarding this code or you have any query then post your query on this Blog.  :)

2 comments: