1

NSUserNotification正在交付,播放给定的声音,但如果我的应用程序不是最顶层的应用程序,则不会在屏幕上直观地显示。

如果我的应用程序在后台,则不会显示通知。如果我的应用程序处于活动状态,它会显示。在这两种情况下,声音都会播放。

这是我发送通知的方式:

NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle: @"hi"];
[notification setSoundName: NSUserNotificationDefaultSoundName];
[notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 3]];
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];

我最重要shouldPresentNotification的是始终呈现它。

[NSUserNotificationCenter defaultUserNotificationCenter].delegate = self;

...

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

OSX 10.10.1 优胜美地

如何使此通知始终显示,就像它始终播放声音一样?

4

1 回答 1

0

我找到了两种让通知始终显示的方法:

删除所有以前的通知

[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];

或者通过更改标识符

notification.identifier = @"com.yourcompany.yourapp.notificationidentifier";
于 2015-02-04T14:52:44.513 回答