简体   繁体   English

无法从锁屏中删除本地通知

[英]Unable to Remove Local Notification from Lockscreen

In my app, at some point I need to display some notification to the user, in case user didn't respond to them, I need to remove that notification. 在我的应用程序中,在某些时候我需要向用户显示一些通知,以防用户没有响应它们,我需要删除该通知。 Now, if I call cancelAllLocalNotifications function it does remove notification from notification center (also removes the alert from Home-screen, when the device is unlocked). 现在,如果我调用cancelAllLocalNotifications函数,它会从通知中心删除通知(当设备解锁时,也会从主屏幕中删除警报)。

But when device is locked and notification is displayed on the lock-screen. 但是当设备被锁定并且锁定屏幕上显示通知时。 After sometime, my app calls cancelAllLocalNotifications function. 一段时间后,我的应用程序调用cancelAllLocalNotifications函数。 Now, this doesn't remove Notification from Lock-screen , however there is no item in notification center. 现在,这不会从锁定屏幕中删除通知 ,但通知中心中没有项目。

Using cancelAllLocalNotifications won't remove the already showed ones. 使用cancelAllLocalNotifications不会删除已经显示的那些。 It cancels all notifications that are scheduled. 它取消了所有已安排的通知。 I don't think there is a way to clear a notification from the lock screen. 我认为没有办法从锁定屏幕清除通知。

I dont know if it was not possible that time, but now you can cancel notification from the lockscreen. 我不知道时间是否可能,但现在你可以取消锁屏的通知。 If anybody needs this now. 如果有人现在需要这个。

If you send a notification you have to store it somewhere to be able to identify it when it should be canceled. 如果您发送通知,则必须将其存储在某个位置,以便能够在取消时识别它。

All you have to do is 你所要做的就是

UIApplication.sharedApplication().cancelLocalNotification(notification)

to identify the notification which should be canceled you can set information in the userinfo property 要识别应取消的通知,您可以在userinfo属性中设置信息

notification.userInfo = ["title": item.title, "UUID": item.UUID]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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