【问题标题】:Mavericks NSUserNotification not sending when app not main当应用程序不是主应用程序时,小牛队 NSUserNotification 未发送
【发布时间】: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


    【解决方案1】:

    尝试摆脱unc.delegate = self;

    【讨论】:

    • 自从我升级到 Mavericks 后,我就需要设置委托并提供上述委托方法,以便让任何东西都显示出来。不知道为什么。
    • 这可能是一些 null 正在干扰它。试试 NSLog(@"%@", note) 看看有没有什么奇怪的地方。我曾经必须明确声明 hasActionButton = NO 才能显示通知。
    • 只是为了确保,您确实也设置了这样的委托? @interface AppDelegate : NSObject {
    • 是的,这样设置了代表。尝试弄乱操作按钮道具。并将任何空字符串设置为空字符串,但没有帮助。
    • 检查一下:只需在[unc deliverNotification:note]; 行之前设置一个断点,当我按下恢复时通知工作。为什么会这样做?
    猜你喜欢
    • 2014-05-15
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 2015-10-30
    • 2015-11-11
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多