记得遵守<NSUserNotificationCenterDelegate>
NSUserNotification *notification=[[NSUserNotification alloc] init];
// 设置提醒时间,倒计时以秒为单位。以下是从现在开始 ?秒以后通知
notification.deliveryDate =[NSDate dateWithTimeIntervalSinceNow:0];
notification.deliveryTimeZone = [NSTimeZone defaultTimeZone];
notification.title = @"XXX";
notification.soundName= NSUserNotificationDefaultSoundName;
// PS:先移出之前已显示的所有通知,否则,相同消息只显示一次
[[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
// 启用通知
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
//returen YES;强制显示(即不管通知是否过多)
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
return YES;
}
更加详细的资料:
https://blog.csdn.net/lovechris00/article/details/78134365
网友评论