アプリが最前面にあるときにユーザー通知を表示したい。以下のコードを見つけましたが、デリゲートの使用方法がわかりません。ブール値を返すだけのようです。
class MyNotificationDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self
}
func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool {
return true
} }
私は次のようないくつかの文を試しました:
var delegate : MyNotificationDelegate = MyNotificationDelegate()
var notification:NSUserNotification = NSUserNotification()
var notificationcenter:NSUserNotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
delegate.userNotificationCenter(notificationcenter, shouldPresentNotification: notification)
ただし、バナーは表示されません。NSUserNotificationCenter
の場合、deliverNotification:
メソッドはバナーを表示する方法であることを知っています。NSUserNotificationCenterDelegate
しかし、プロトコルについてはよくわかりません。
通知バナーを常に表示するにはどうすればよいですか?