简体   繁体   English

如何使用[CWWiFiClient startMonitoringEventWithType:error:]获取SSID更改通知

[英]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.

相关问题 使用startMonitoringEventWithType:error:努力检测wifi SSID的变化 - using startMonitoringEventWithType: error: in the effort to detect wifi SSID change 使用CWWiFiClient禁用WiFi - Disable WiFi with CWWiFiClient 获取NSStatusItem框架更改的通知? - Get Notification of NSStatusItem frame change? 苹果系统。 Qt 如何获取所有可用WiFi网络的SSID,BSSID和频道 - Mac OS. Qt. How to get SSID, BSSID and channel of all available WiFi networks 在 Mac OS X 上通过 shell 脚本获取无线 SSID - Get wireless SSID through shell script on Mac OS X 如何在Mac上使用Apple Push Notification? - How to Use Apple Push Notification on Mac? 如何使用 AppleScript 获取通知副标题/正文? - How to get notification subtitle/body using AppleScript? 当应用程序在后台运行时,如何在Mac中获得有关鼠标和键盘使用的通知? - How to get notification of mouse and keyboard use in Mac when app is running in background? 如何更改 macos catalina 上的通知关闭/操作按钮文本 - how to change the notification close/action button text on macos catalina 根据 SSID 更改 MacOS 位置 - 无法让脚本自动运行 - Changing MacOS Location based on SSID - can't get script to run automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM