开发者

USB Detection on MAC cocoa application using NSWorkspace notification

开发者 https://www.devze.com 2023-04-07 02:53 出处:网络
I am trying to implement USB detection using NSworkspacenotification method, using this code int main (int argc, const char * argv[])

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

精彩评论

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