开发者

USB Detection on MAC cocoa application using NSWorkspace notification

I am trying to implement USB detection using NSworkspacenotification method, using this code

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;
}

This code does not detect USB and o开发者_开发问答utputs:

Hello, World!
Program ended with exit code: 0

What's wrong with this code?


You have added no input sources or timers to your run loop, so it's exiting immediately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜