スウィフト 2.3 では:
func userNotificationCenter(center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
var notificationStillPresent: Bool
repeat {
notificationStillPresent = false
for nox in NSUserNotificationCenter.defaultUserNotificationCenter().deliveredNotifications {
if nox.identifier == notification.identifier {
notificationStillPresent = true
break
}
}
if notificationStillPresent {
let _ = NSThread.sleepForTimeInterval(0.20)
}
} while notificationStillPresent
dispatch_async(dispatch_get_main_queue()) {
self.notificationHandlerFor(notification)
}
}
}
PS: これは、いくつかのケースで発生する可能性のある終了イベントを検出する方法であることにも注意してください。
- をクリックし
otherButton
て閉じます
Clear All
通知センターのボタンをクリックします
PS 2: を使用している場合、たとえば 1 分、アレイdeliveryRepeatInterval
には複数の通知があり、 1 つだけが表示されます。deliveredNotifications
解任は、複数のコールバックをトリガーします。
PS 3: クリックするactionButton
と、解雇コールバックもトリガーされます