简体   繁体   中英

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.

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]; and after i resume, the notification always works. Whaaa?

尝试摆脱unc.delegate = self;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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