0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(myReachabilityDidChangedMethod)
                                             name:kReachabilityChangedNotification
                                           object:nil];
Reachability *reachability;
reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

I have the above block of code in my AppDelegate to create an observer for reachability, which aimed to trigger myReachabilityDidChangedMethod through the application.

However, myReachabilityDidChangedMethod cannot be triggered which is located in AppDelegate, when I turn on or off my wifi, I tested it both on simulator and ipad, but did't have any response on both.

Shing
  • 1,255
  • 1
  • 10
  • 18

1 Answers1

-1

To trigger your method, you need to post a notification :

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

By the way, if I'm not mistaken, when you register your notification, kReachabilityChangedNotification should be written as a string @"kReachabilityChangedNotification"

moxy
  • 1,634
  • 1
  • 11
  • 19
  • Shouldn't the Reachability class itself post the notification automatically? – Shing Jul 11 '12 at 19:30
  • @Shing, no it won't. User have to explicitly add a item to the notification should they need it. Also make sure to remove the notification when app quits. Use this to remove ALL notification: `[[NSNotificationCenter defaultCenter] removeObserver:self];` OR this to remove specific notification: `[[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];` – Steven Aug 20 '12 at 13:59