简体   繁体   English

当应用程序不是主要的时,Mavericks NSUserNotification不发送

[英]Mavericks NSUserNotification not sending when app not main

Notifications are delivering normal when the app is the main app, but when it loses focus notifications aren't getting delivered. 当应用程序是主应用程序时,通知正常传递,但是当失去焦点时,则不会传递通知。 I've tried logging calls from (BOOL)userNotificationCenter:shouldPresentNotification: and it i'm not getting anything at all when in the background, but logs as expected when main. 我试过记录(BOOL)userNotificationCenter:shouldPresentNotification:在后台我什么也没收到,但是在main时却按预期记录。

Code: 码:

NSUserNotification * note = [[NSUserNotification alloc] init];
NSUserNotificationCenter * unc = [NSUserNotificationCenter defaultUserNotificationCenter];
unc.delegate = self;

note.title = track.title;
note.subtitle = track.artist;

[unc deliverNotification:note];

Delegate method 委托方法

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
    return YES;
}

Edit 编辑

I added a breakpoint before [unc deliverNotification:note]; 我在[unc deliverNotification:note];之前添加了一个断点[unc deliverNotification:note]; and after i resume, the notification always works. 在我恢复后,通知始终有效。 Whaaa? Whaaa?

尝试摆脱unc.delegate = self;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM