简体   繁体   中英

How to prevent a delivered NSUserNotification Popup from removing a previous Notification Popup

I'm trying to get 2 notifications to pop up at once, stacked on top of eachother, but when I deliver the second notification, it pushes the first popup out of the display.

     NSUserNotification *notification = [[NSUserNotification alloc] init];
     notification.title = @"1";
     notification.informativeText = [NSString stringWithFormat:@"First Popup"];
     notification.soundName = NSUserNotificationDefaultSoundName;
     [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];

     NSUserNotification *notification2 = [[NSUserNotification alloc] init];
     notification2.title = @"2";
     notification2.informativeText = [NSString stringWithFormat:@"Second Popup"];
     notification2.soundName = NSUserNotificationDefaultSoundName;
     [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification2];

Is there a flag or something I could set to stop the second popup from removing the first one from my display? (They both still exist in the notification center)

You have to enable notifications to show as Alerts in the Notifications in System Preference .

带关闭按钮的弹出窗口

and then you can remove/dismiss the notifications as/if you want using:

- (void)removeDeliveredNotification:(NSUserNotification *)notification;

You can use Growl also for the purpose but i don't know if that will show notifications in notification center. I don't know any other way of doing this and will love to learn that.

通知中心

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM