我正在尝试更新已交付通知(警报)的副标题中的字符串,我正在使用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)