gpt4 book ai didi

macos - 如何更新交付的 NSUserNotification 中的副标题?

转载 作者:行者123 更新时间:2023-12-03 16:20:15 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com