I want to display user notifications while the app is frontmost. I found the code below, but I'm not sure how to use the delegate: it seems to just return a boolean value.
class MyNotificationDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self
}
func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool {
return true
} }
I have tried some sentences like:
var delegate : MyNotificationDelegate = MyNotificationDelegate()
var notification:NSUserNotification = NSUserNotification()
var notificationcenter:NSUserNotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
delegate.userNotificationCenter(notificationcenter, shouldPresentNotification: notification)
But it won't show the banner.
I know that for NSUserNotificationCenter
, the deliverNotification:
method is the way to show the banner. But I'm not sure about the NSUserNotificationCenterDelegate
protocol.
How can I always show the notification banner?