我的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 Yosemite
如何使此通知始终显示,就像它总是播放声音一样?
发布于 2015-02-04 22:52:45
我发现了两种使通知始终显示的方法:
使用删除所有以前的通知
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];或者通过改变标识符
notification.identifier = @"com.yourcompany.yourapp.notificationidentifier";https://stackoverflow.com/questions/28077054
复制相似问题