Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Detect if an Internet Connection exists in iPhone using (ARC and GCD compatible) class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 217
    Comment on it

    Hi Readers,

    Below are steps you need to follow when you are checking if their is an Active Internet connection in an Iphone using (ARC and GCD compatible) class.

    1) Add SystemConfiguration framework to the project but dont worry about including it anywhere

    2) Add T.Millions version of Reachability.h and Reachability.m to the project.

    3) Update the interface section:

    #import "Reachability.h"
    // Add this to the interface in the .m file of your view controller
    @interface MyViewController ()
    {
    
        Reachability *internetReachableFoo;
    
    }
    @end
    

    4) Then implement this method in the .m file of your view controller which you can call:

    **// Checks if we have an internet connection or not
    
    - (void)testInternetConnection
    
    {   
        internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
    
        // Internet is reachable
    
        internetReachableFoo.reachableBlock = ^(Reachability*reach)
        {
            // Update the UI on the main thread
    
            dispatch_async(dispatch_get_main_queue(), ^{
    
                NSLog(@"Yayyy, we have the interwebs!");
    
            });
    
        };
        // Internet is not reachable
        internetReachableFoo.unreachableBlock = ^(Reachability*reach)
        {
            // Update the UI on the main thread
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"Someone broke the internet :(");
            });
        };
        [internetReachableFoo startNotifier];
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: