How to use [CWWiFiClient startMonitoringEventWithType:error:] to get SSID change notification
How to use [CWWiFiClient startMonitoringEventWithType:error:] to get SSID change notification
我试图在网络为 changed.For 时在我的 OS X 机器中收到通知,这是我添加的 coreWLAN.framewok。在那里我找到了一种方法
/*!
* @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;
但我不知道如何使用它。请在这里发表评论
这与您在上面想要实现的工作相同。它会在 SSID 更改时通知您
为了获得这些通知,您需要保留 CWInterface 的一个实例。你的 .h 看起来像这样
#import <Cocoa/Cocoa.h>
@class CWInterface;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (retain) CWInterface *wirelessInterface;
@end
然后在您的 .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");
}
@结束
使用接口名称 en1 或 en0 时要小心。通过给 ifconfig
查看存在哪个接口 ip 来检查您的系统
我试图在网络为 changed.For 时在我的 OS X 机器中收到通知,这是我添加的 coreWLAN.framewok。在那里我找到了一种方法
/*!
* @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;
但我不知道如何使用它。请在这里发表评论
这与您在上面想要实现的工作相同。它会在 SSID 更改时通知您
为了获得这些通知,您需要保留 CWInterface 的一个实例。你的 .h 看起来像这样
#import <Cocoa/Cocoa.h>
@class CWInterface;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (retain) CWInterface *wirelessInterface;
@end
然后在您的 .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");
}
@结束 使用接口名称 en1 或 en0 时要小心。通过给 ifconfig
查看存在哪个接口 ip 来检查您的系统