取消并重新安排本地通知(快速)

编程入门 行业动态 更新时间:2024-10-17 21:20:01
本文介绍了取消并重新安排本地通知(快速)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试显示时间间隔为1天(24小时)的本地通知,并且该通知可以正常工作,但是现在我想取消特定日期的通知.我今天尝试过,但是似乎没有用.我的通知仍然出现,这是我为取消通知所做的事情:

I'm trying to show a local notification with a time interval of 1 day (24 hours) and its working fine but now I want to cancel notification for a specific day. I tried(today) this but it didn't seem to work. My notification is still appearing this is what I have done for cancelling the notification:

let appNotification = appDelegate!.notification UIApplication.sharedApplication().cancelLocalNotification(appNotification)

这是在appDelegate中安排通知的方式:

This is how am scheduling the notification in appDelegate :

//scheduling notification dateComp.year = 2015; dateComp.month = 01; dateComp.day = 20; dateComp.hour = 21; dateComp.minute = 05; dateComp.timeZone = NSTimeZone.systemTimeZone() notification.category = "FIRST_CATEGORY" notification.alertBody = "my daily notiification ?" notification.soundName = UILocalNotificationDefaultSoundName notification.fireDate = finalFireDate notification.repeatInterval = NSCalendarUnit.Day let dateNow = NSDate() let noticalendar = NSCalendar.currentCalendar() let hour = calendarponent(NSCalendarUnit.Hour, fromDate: dateNow) UIApplication.sharedApplication().scheduleLocalNotification(notification)

我不知道为什么无法取消通知,因为有任何丢失或做错的事情,请告诉我.

I don't know why am not able to cancel the notification there's anything that is missing or doing wrong, please let me know.

推荐答案

尝试此代码

var app:UIApplication = UIApplication.sharedApplication() for oneEvent in app.scheduledLocalNotifications! { var notification = oneEvent as UILocalNotification if notification.fireDate == "your date" { //Cancelling local notification app.cancelLocalNotification(notification) break; } }

更多推荐

取消并重新安排本地通知(快速)

本文发布于:2023-07-14 10:03:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104045.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新安   快速   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!