它与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;