在 OS X 中检测已安装的 USB 设备
Detecting mounted USB devices in OS X
所以我试图在我的 Mac Mini
上的 OS X 中检测已安装和未安装的 USB 设备
我已经关注了其他指南,但似乎没有收到任何通知。
这是我拥有的代码,我也曾尝试将其放置在视图控制器中 class 但无济于事。
@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];
}
您的代码尝试登录的方式不正确,NSLog
是您需要的:
- (void)deviceMounted: (NSNotification *) notification
{
NSLog(@"Mounted");
}
- (void)deviceUnmounted: (NSNotification *) notification
{
NSLog(@"Unmounted");
}
结果:
2015-02-27 04:07:00.593 notify[32431:16256290] Mounted
2015-02-27 04:07:11.587 notify[32431:16256290] Unmounted
所以我试图在我的 Mac Mini
上的 OS X 中检测已安装和未安装的 USB 设备我已经关注了其他指南,但似乎没有收到任何通知。
这是我拥有的代码,我也曾尝试将其放置在视图控制器中 class 但无济于事。
@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];
}
您的代码尝试登录的方式不正确,NSLog
是您需要的:
- (void)deviceMounted: (NSNotification *) notification
{
NSLog(@"Mounted");
}
- (void)deviceUnmounted: (NSNotification *) notification
{
NSLog(@"Unmounted");
}
结果:
2015-02-27 04:07:00.593 notify[32431:16256290] Mounted
2015-02-27 04:07:11.587 notify[32431:16256290] Unmounted