简体   繁体   中英

Activate NSWindow with NSUserNotification

My scenario: I have an app that sends a notification to the OS X Notification Center with a button. This notification is to tell me when someone rings our dock doorbell. The button is suppose to pull up a NSWindow that shows our dock camera. I can get the window to come up with a NSButton within the app, but I can't get it to come up with the notification button.

I have tried:

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
    if ([notification.title isEqualToString:@"Doorbell"]) {
        [DockCameraWindow makeKeyAndOrderFront:nil];
        NSLog(@"CameraWindow");
    }
    [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
}

The log shows up, however the window doesn't. My application however does take the front app status.

你有没有尝试过-

[NSApp activateIgnoringOtherApps:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM