1

My NSUserNotification is being delivered, playing the given sound, but doesn't show visually on the screen if my app is not the top-most application.

If my application is in the background, the notification does not show. If my application is active, it shows. In both cases the sound plays.

Here is how I'm sending the notification:

NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle: @"hi"];
[notification setSoundName: NSUserNotificationDefaultSoundName];
[notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 3]];
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];

And I am overriding shouldPresentNotification to always present it.

[NSUserNotificationCenter defaultUserNotificationCenter].delegate = self;

...

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
    return YES;
}

OSX 10.10.1 Yosemite

How do I make this notification always display, just like it always plays the sound?

tenfour
  • 36,141
  • 15
  • 83
  • 142

1 Answers1

0

I found two ways to make a notification always display:

Remove all previous notifications with

[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];

Or by changing the identifier

notification.identifier = @"com.yourcompany.yourapp.notificationidentifier";
Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38
Kane Cheshire
  • 1,654
  • 17
  • 20