Objective c NSUserNotification发出声音但不显示
MyObjective c NSUserNotification发出声音但不显示,objective-c,macos,nsusernotification,Objective C,Macos,Nsusernotification,MyNSUserNotification正在发送,播放给定的声音,但如果我的应用程序不是最顶级的应用程序,则不会在屏幕上显示 如果我的应用程序在后台,则不会显示通知。如果我的应用程序处于活动状态,则会显示。在这两种情况下,声音都会播放 以下是我发送通知的方式: NSUserNotification *notification = [[NSUserNotification alloc] init]; [notification setTitle: @"hi"]; [notification set
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;
OSX 10.10.1约塞米蒂
如何使此通知始终显示,就像它始终播放声音一样?我找到了两种使通知始终显示的方法: 使用删除以前的所有通知
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
或者通过更改标识符
notification.identifier = @"com.yourcompany.yourapp.notificationidentifier";
notification.identifier = @"com.yourcompany.yourapp.notificationidentifier";