【发布时间】:2013-12-06 21:46:00
【问题描述】:
当应用程序是主应用程序时,通知会正常发送,但当它失去焦点时,通知不会发送。我已经尝试记录来自(BOOL)userNotificationCenter:shouldPresentNotification: 的调用,但在后台我什么也没有得到,但在 main 时按预期记录。
代码:
NSUserNotification * note = [[NSUserNotification alloc] init];
NSUserNotificationCenter * unc = [NSUserNotificationCenter defaultUserNotificationCenter];
unc.delegate = self;
note.title = track.title;
note.subtitle = track.artist;
[unc deliverNotification:note];
委托方法
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
return YES;
}
编辑
我在[unc deliverNotification:note]; 之前添加了一个断点,在我恢复之后,通知始终有效。哇?
【问题讨论】:
标签: objective-c macos cocoa