Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSUserNotification发出声音但不显示_Objective C_Macos_Nsusernotification - Fatal编程技术网

Objective c NSUserNotification发出声音但不显示

Objective c NSUserNotification发出声音但不显示,objective-c,macos,nsusernotification,Objective C,Macos,Nsusernotification,MyNSUserNotification正在发送,播放给定的声音,但如果我的应用程序不是最顶级的应用程序,则不会在屏幕上显示 如果我的应用程序在后台,则不会显示通知。如果我的应用程序处于活动状态,则会显示。在这两种情况下,声音都会播放 以下是我发送通知的方式: NSUserNotification *notification = [[NSUserNotification alloc] init]; [notification setTitle: @"hi"]; [notification set

My
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";