【发布时间】:2015-02-27 20:01:48
【问题描述】:
所以我试图在我的 Mac Mini 上检测 OS X 中已安装和未安装的 USB 设备
我已按照其他指南进行操作,但我似乎没有收到任何通知。
这是我拥有的代码,我也尝试将其放置在视图控制器类中,但无济于事。
@implementation AppDelegate
- (void)deviceMounted: (NSNotification *) notification
{
NSLog(@"Mounted");
}
- (void)deviceUnmounted: (NSNotification *) notification
{
NSLog(@"Unmounted");
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSNotificationCenter *notificationCenter2 = [[NSWorkspace sharedWorkspace] notificationCenter];
// Notification for Mountingthe USB device
[notificationCenter2 addObserver:self selector:@selector(deviceMounted:) name:NSWorkspaceDidMountNotification object:nil];
// Notification for Un-Mountingthe USB device
[notificationCenter2 addObserver:self selector:@selector(deviceUnmounted:) name:NSWorkspaceDidUnmountNotification object:nil];
}
【问题讨论】: