3

I'm trying to update the string in the subtitle of a delivered notification (alert), I'm doing it with an NSTimer like this:

[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";
    }];
}

The code is executing correctly every 5 seconds. But the shown subtitle in the notification alert does not change.

Is there some way to force a "redraw" like setNeedsDisplay or something similar?

Thanks.

edgarjs
  • 506
  • 2
  • 9

1 Answers1

2

I know this post is somewhat old, but I was recently trying to figure out the same thing, but ended up needing to delete the existing notification and adding a new one with the same title.

I use a NSUUID in the notification's identifier field when I create them and then find the existing one using something like (in Swift):

var notif = NSUserNotification()
notif.identifier = <Id To Search For>
NSUserNotificationCenter.defaultUserNotificationCenter().removeScheduledNotification(notif)
NSUserNotificationCenter.defaultUserNotificationCenter().removeDeliveredNotification(notif)
JG in SD
  • 5,427
  • 3
  • 34
  • 46
  • 1
    But that does the slide animation again right? My main goal is to do something like the Reminders' notification, if you leave the notification there, it just updates the subtitle "9 minutes ago" and so on. I couldn't find anything in the docs for that. – edgarjs Nov 19 '14 at 18:21