[英]How to use [CWWiFiClient startMonitoringEventWithType:error:] to get SSID change notification
I was trying to get a notification in my OS X machine whenever network is changed.For this i added coreWLAN.framewok. 每当更改网络时,我都试图在OS X机器中收到通知。为此,我添加了coreWLAN.framewok。 There i found a way as
在那里我找到了一种方法
/*!
* @method
*
* @param interfaceName
* The name of the Wi-Fi interface.
*
* @abstract
* Invoked when the current SSID changes.
*
* @discussion
* Use -[CWWiFiClient startMonitoringEventWithType:error:] with the CWEventTypeSSIDDidChange event type
* to register for SSID event notifications.
* Use -[CWInterface ssidData] or -[CWInterface ssid] to query the current SSID.
*/
- (void)ssidDidChangeForWiFiInterfaceWithName:(NSString *)interfaceName;
But i am not aware of how to use it. 但是我不知道如何使用它。 Please some one comment here
请在这里发表一些评论
This does the same job what you want to achieve in above. 这完成了您上面想要实现的任务。 It notifies you whenever SSID changes
SSID更改时通知您
In order for you to get those notifications you need to be holding on to an instance of CWInterface. 为了获得这些通知,您需要保留CWInterface实例。 Your .h would look like this
您的.h看起来像这样
#import <Cocoa/Cocoa.h>
@class CWInterface;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (retain) CWInterface *wirelessInterface;
@end
Then in your .m file would look like this 然后在您的.m文件中将如下所示
#import "AppDelegate.h"
#import <CoreWLAN/CoreWLAN.h>
@implementation AppDelegate
@synthesize window = _window;
@synthesize wirelessInterface;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[[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];
self.wirelessInterface = [CWInterface interfaceWithName:@"en1"];
}
-(void) handleNotification:(NSNotification*) notification
{
NSLog(@"Notification Received");
}
@end Take care while using interface name en1 or en0. @end在使用接口名称en1或en0时要小心。 Check your sysytem by seeing to which interface ip is present by giving ifconfig
通过给ifconfig查看哪个接口ip来检查系统
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.