【发布时间】:2018-10-19 11:49:27
【问题描述】:
我有一个使用本地通知的 macOS Swift 应用程序。这是发送这些的一个小方法:
func sendPushMessage(title: String, message: String, userInfo: [String:Any]) {
let notification: NSUserNotification = NSUserNotification()
notification.title = title
notification.informativeText = message
notification.userInfo = userInfo
notification.soundName = NSUserNotificationDefaultSoundName
notification.deliveryDate = Date()
self.center.scheduledNotifications = [notification]
}
这工作了很长时间,我已经收到了我的所有通知(以及所有通知都显示在通知中心)。但实际上最新的通知会覆盖之前的通知。假设只有一个通知槽总是被最新通知覆盖。
在我的通知中心,也只有一个通知可见(最新的),而不是所有收到的通知。我不知道什么时候“停止工作”,但我想一两个月前?我还在 10.13.6 高山上。
通知设置正确。
【问题讨论】:
-
self.center.scheduledNotifications = [notification]看起来很奇怪。在我看来,你现在得到的行为是正常的,你得到的行为很奇怪(macOS 的变化?)。我会使用self.center.scheduledNotifications = self.center.scheduledNotifications + [notification](即结合所有当前计划并附加新的)或self.center.scheduleNotification(notification),它应该“附加”它。 -
没有变化,但感谢您的建议。
标签: swift macos push-notification notifications uilocalnotification