我正在尝试使用 NSworkspacenotification 方法实现 USB 检测,使用此代码
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[[NSWorkspace sharedWorkspace] notificationCenter]addObserver: [NotifTarget class] selector: @selector(mountNotification:) name: NSWorkspaceDidMountNotification object: nil];
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver: [NotifTarget class]
selector: @selector(unmountNotification:)
name: NSWorkspaceDidUnmountNotification object: nil];
[[NSRunLoop currentRunLoop] run];
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
此代码不检测 USB 和输出:
Hello, World!
Program ended with exit code: 0
这段代码有什么问题?
最佳答案
您尚未向运行循环添加任何输入源或计时器,因此它会立即退出。
关于objective-c - 使用 NSWorkspace 通知对 MAC cocoa 应用程序进行 USB 检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7545730/