Constantly Listen for Internet Reachability?

Josh Kahane

I understand how I can test internet reachability in my app, but what i need to do is constantly listen for reachability, app wide. So if any point anywhere in the app the connection status changes, I can react.

How would I achieve something like this?

Nishant Tyagi

You need to add an observer for reachability change notification :

Firstly import in your class: #import "Reachability.h"

then add observer :

   [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];


-(BOOL)reachabilityChanged:(NSNotification*)note
{
    BOOL status =YES;
    NSLog(@"reachabilityChanged");

    Reachability * reach = [note object];

    if([reach isReachable])
    {
        //notificationLabel.text = @"Notification Says Reachable"
        status = YES;
        NSLog(@"NetWork is Available");
    }
    else
    {
        status = NO;
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"You are not connected to the internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    return status;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

constantly "listen" to website using python

From Dev

AFNetworking Reachability not recognizing internet connection for first time

From Dev

Why Reachability Manager can not detect internet?

From Dev

No internet connection alert using AFNetworking 2 and Reachability

From Dev

Reachability vs NSURLSession response to detect internet connection

From Dev

How check WatchOS 2 connected (reachability) to the internet?

From Dev

Why Reachability Manager can not detect internet?

From Dev

Connecting wifi without internet not recognised with NetworkReachabilityManager or Reachability

From Dev

Macbook Pro loses Internet constantly for a couple seconds

From Dev

How to Change the status bar color using ios with swift on internet reachability?

From Dev

Check for active internet connection throughout the app in ios using Reachability class

From Dev

VBA, constantly listen to changes in cells that meet specific criteria

From Dev

Constantly Losing Internet Connection 2Wire HGV3801

From Dev

What is the best way to check internet connection in background constantly?

From Dev

Constantly lost of the internet connection with the wifi after install Ubuntu 16.04

From Dev

Network link conditioner on 100% packet loss - why I am getting internet reachability status wrong?

From Dev

How can I display message to user as soon as internet disappears using reachability with afnetworking 2.0

From Dev

By industry practices, should I check internet reachability before making API call or during API call in Alamofire

From Dev

Reachability not working

From Dev

Reachability iOS

From Dev

Reachability not work

From Dev

Notify user reachability (Ashley Mills' Reachability)

From Dev

AFNetworking reachability status not changing

From Dev

Reachability in graph - C

From Dev

IOS Reachability notification in Background

From Dev

AFNetworking Reachability iOS

From Dev

Display an alert of reachability status

From Dev

Reachability and signal strength

From Dev

AFNetworking 2.0 Reachability not working

Related Related

  1. 1

    constantly "listen" to website using python

  2. 2

    AFNetworking Reachability not recognizing internet connection for first time

  3. 3

    Why Reachability Manager can not detect internet?

  4. 4

    No internet connection alert using AFNetworking 2 and Reachability

  5. 5

    Reachability vs NSURLSession response to detect internet connection

  6. 6

    How check WatchOS 2 connected (reachability) to the internet?

  7. 7

    Why Reachability Manager can not detect internet?

  8. 8

    Connecting wifi without internet not recognised with NetworkReachabilityManager or Reachability

  9. 9

    Macbook Pro loses Internet constantly for a couple seconds

  10. 10

    How to Change the status bar color using ios with swift on internet reachability?

  11. 11

    Check for active internet connection throughout the app in ios using Reachability class

  12. 12

    VBA, constantly listen to changes in cells that meet specific criteria

  13. 13

    Constantly Losing Internet Connection 2Wire HGV3801

  14. 14

    What is the best way to check internet connection in background constantly?

  15. 15

    Constantly lost of the internet connection with the wifi after install Ubuntu 16.04

  16. 16

    Network link conditioner on 100% packet loss - why I am getting internet reachability status wrong?

  17. 17

    How can I display message to user as soon as internet disappears using reachability with afnetworking 2.0

  18. 18

    By industry practices, should I check internet reachability before making API call or during API call in Alamofire

  19. 19

    Reachability not working

  20. 20

    Reachability iOS

  21. 21

    Reachability not work

  22. 22

    Notify user reachability (Ashley Mills' Reachability)

  23. 23

    AFNetworking reachability status not changing

  24. 24

    Reachability in graph - C

  25. 25

    IOS Reachability notification in Background

  26. 26

    AFNetworking Reachability iOS

  27. 27

    Display an alert of reachability status

  28. 28

    Reachability and signal strength

  29. 29

    AFNetworking 2.0 Reachability not working

HotTag

Archive