美文网首页
NSUserNotification右上角弹出通知

NSUserNotification右上角弹出通知

作者: 皮蛋豆腐酱油 | 来源:发表于2019-10-25 16:22 被阅读0次
    记得遵守<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

相关文章

网友评论

      本文标题:NSUserNotification右上角弹出通知

      本文链接:https://www.haomeiwen.com/subject/doasvctx.html