3

In my app I want to detect network status changes to do some operations at that time. I have added following code in app-delegate. when I turn on net connection "networkStatusChanged:" method called once which is correct. and when I turn off net-connection it calls twice. can anyone help me to find out the problem please......

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(networkStatusChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];
    reachability = [[Reachability reachabilityForInternetConnection] retain];
    [reachability startNotifier];
Ankur
  • 5,086
  • 19
  • 37
  • 62
Vaisakh
  • 1,088
  • 1
  • 8
  • 14
  • 1
    Where are you calling it? You should put this in the `init` or `viewdidLoad` of your class. Remember to remove the observer from that class when you deallocate it. Btw, if you were in WIFI and then switch it off probably it gets called twice because as @sangony said first time because it lost the wifi signal and second time got cell data. – Mr. Frank May 02 '13 at 13:20
  • So what should i do to make it call only once when i loss network ? – Vaisakh May 06 '13 at 05:07

1 Answers1

1

It is probably doing it once for a lost WiFi connection and a second time for a lost cell data connection.

sangony
  • 11,636
  • 4
  • 39
  • 55