Elbimio
Elbimio

Reputation: 1041

Cocoa: Forcing an NSUserNotification while app is frontmost

Fairly straightforward, I have an app that should send a notification but it will not do so if the application is frontmost. From the NSUserNotificationCenter class reference:

The user notification center reserves the right to decide if a delivered user notification is presented to the user. For example, it may suppress the notification if the application is already frontmost (the delegate can override this action).

From what I can gather it has to do with the userNotificationCenter:shouldPresentNotification: method that is shown in the NSUserNotificationCenterDelegate protocol reference but I can't figure out how to implement it. I already set my class to be the NSUserNotificationCenterDelegate so that's not it.

Any ideas?

EDIT: In the class I set as the NSUserNotificationCenterDelegate I use this to try to override the original method, which defaults as NO if the app is frontmost:

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

But nothing happens.

Upvotes: 4

Views: 1795

Answers (1)

Prakash Jat
Prakash Jat

Reputation: 589

NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; [center scheduleNotification:notification]; center.delegate = self;

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

Upvotes: 5

Related Questions