简体   繁体   English

使用NSUserNotification激活NSWindow

[英]Activate NSWindow with NSUserNotification

My scenario: I have an app that sends a notification to the OS X Notification Center with a button. 我的情况是:我有一个应用程序,它通过一个按钮将通知发送到OS X通知中心。 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. 该按钮假定是拉起一个显示我们停靠摄像机的NSWindow的。 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. 我可以让该窗口在应用程序中提供一个NSButton,但是我不能让它提供通知按钮。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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