Musthafa
Musthafa

Reputation: 63

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 outputs:

Hello, World!
Program ended with exit code: 0

What's wrong with this code?

Upvotes: 0

Views: 457

Answers (1)

user149341
user149341

Reputation:

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

Upvotes: 1

Related Questions