如何NSUserNotificationCenterDelegate迅速地建立代表?
NSUserNotificationCenterDelegate
它与obj-c没什么不同。首先,您必须在类声明中指定协议,如下所示:
class MyClass: NSUserNotificationCenterDelegate
该实现将如下所示:
// NSUserNotificationCenterDelegate implementation func userNotificationCenter(center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification) { //implementation } func userNotificationCenter(center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification) { //implementation } func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool { //implementation return true }
当然,您必须设置委托。例如:
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self;