[英]How to show User notification twice on single button click using NSUserNotification?
[英]NSUserNotification makes sound but does not show
我的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優勝美地
如何使此通知始終顯示,就像它始終播放聲音一樣?
我發現使通知始終顯示的兩種方法:
刪除所有以前的通知
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
或通過更改標識符
notification.identifier = @"com.yourcompany.yourapp.notificationidentifier";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.