Harsh
Harsh

Reputation: 666

Notification is not being called in Reachability

I have used Andrew's modified Reachability class.

-(void)viewDidLoad

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

When data is downloading I turn AirPort off. But checkNetworkStatus is not being called. Am I missing something. Please help me. This problem driving me nuts. Thanks in advance.

Upvotes: 5

Views: 6616

Answers (4)

sabiland
sabiland

Reputation: 2614

This worked for me (Swift):

func handleNetworkChange(notification:NSNotification) { ... }

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("handleNetworkChange:"), name: kReachabilityChangedNotification, object: nil)
ReachabilityChecker = Reachability.reachabilityForInternetConnection()
ReachabilityChecker!.startNotifier()

Upvotes: 2

Robert Mao
Robert Mao

Reputation: 1919

I have exactly the same issue, Apple's example works great, so I end up replace Reachability class with Apple's version, everything works great. This costed me almost 2 hours.

Simply replace your Reachability.h, .m from Apple's example, everything should just worked.

Upvotes: 2

rckoenes
rckoenes

Reputation: 69499

Did you tell the reachability instance to start broadcasting notifications?

Reachability *internetReachable = [Reachability reachabilityForInternetConnection];
// This will tell the notifier to start sending notifications
[internetReachable startNotifier];

Upvotes: 11

put it in this sequence

in ur view did load

First register

then

post that notification

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


[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];

Upvotes: 2

Related Questions