小编典典

代表们迅速?

swift

如何NSUserNotificationCenterDelegate迅速地建立代表?


阅读 310

收藏
2020-07-07

共1个答案

小编典典

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