我正在尝试更新已发送通知(警报)的副标题中的字符串,我使用 NSTimer
执行此操作,如下所示:
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(updateSubtitle)
userInfo:nil
repeats:YES];
- (void)updateSubtitle
{
[[NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications
enumerateObjectsUsingBlock:^(NSUserNotification *notification, NSUInteger idx, BOOL *stop) {
notification.subtitle = @"new subtitle";
}];
}
代码每 5 秒正确执行一次。但通知警报中显示的副标题不会改变。
是否有某种方法可以强制“重绘”,例如 setNeedsDisplay
或类似的东西?
谢谢。
最佳答案
我知道这篇文章有点旧,但我最近试图弄清楚同样的事情,但最终需要删除现有的通知并添加一个具有相同标题的新通知。
当我创建通知时,我在通知的标识符字段中使用 NSUUID,然后使用类似(在 Swift 中)的方式查找现有的通知:
var notif = NSUserNotification()
notif.identifier = <Id To Search For>
NSUserNotificationCenter.defaultUserNotificationCenter().removeScheduledNotification(notif)
NSUserNotificationCenter.defaultUserNotificationCenter().removeDeliveredNotification(notif)
关于macos - 如何更新交付的 NSUserNotification 中的副标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24514996/