When my class initializes, it adds itself as an observer for many different Wi-Fi notifications. For some reason, the selector does not work when any of these events occur. Any ideas? Thanks in advance.
-(id) init { if (self) { sself = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWModeDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWSSIDDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWBSSIDDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWCountryCodeDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWLinkDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:CWPowerDidChangeNotification object:nil];
UPDATE: Here is the handleNotification method:
-(void) handleNotification:(NSNotification*) notification { NSLog(@"Notification Received"); }
I have included the CoreWLAN framework in my project:
I downloaded CoreWLANWirelessManager.app and this is what I use for reference. Oddly enough, the Apple code uses outdated notifications, and it still works. I tried using the new API and the deprecated API without success. I'm not sure if I can post their code here, but literally there is no difference. The selector has the same name.
Please feel free to contact for further refinement.
UPDATE (after Dustin's answer): I created a new project, hoping to isolate the problem. I installed my .h and .m files in the same way as you described. Unfortunately, I still do not receive any notifications. To show you that I'm not lying (or crazy), I included two (rather crowded) screenshots that were taken during the same work. Please note: (1. I have a breakpoint in the handleNotification method: the application never stops. (2. I turned on the network window to show that my Mac really changed the Wi-Fi networks during this runtime. (3. Nothing not NSLoged
Network 1:
Network 2:
UPDATE May 17, 2012 Dustin answered correctly, but the name of the Wi-Fi interface varies depending on what equipment the application is running on. In my case (MacBook Air, no ethernet) my Wi-Fi is en0 instead of en1. I managed to capture the plst configuration file from my moms iMac, and the Wi-Fi is called en1. Ethernet - en0. Thank you all for your help.
source share