1

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.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
cookdoeyl
  • 15
  • 2

1 Answers1

2

Did you try this :--

[NSApp activateIgnoringOtherApps:YES];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • You may have to help me. I placed this above [DockCameraWindow makeKeyAndOrderFront:nil]; Is this the correct place for it? – cookdoeyl Nov 01 '13 at 19:12
  • Notifications will only be displayed when your application isn't the key application. If you want your notifications to display regardless of if your application is key or not, you'll need to specify a delegate for NSUserNotificationCenter and override the delegate method userNotificationCenter:shouldPresentNotification: so that it returns YES. – Hussain Shabbir Nov 02 '13 at 05:31
  • Did you implement like this in your code - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; } - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{ return YES; } – Hussain Shabbir Nov 02 '13 at 05:33
  • Hussain, I had your code already in my app. My notification is displaying, it's when I try to activate it that it partially doesn't work. Like stated above, my NSLog(@"CameraWindow") fires however my DockCameraWindow does not appear. – cookdoeyl Nov 03 '13 at 01:40