Unable to Remove Local Notification from Lockscreen - ios

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).
But when device is locked and notification is displayed on the lock-screen. After sometime, my app calls cancelAllLocalNotifications function. 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. 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
notification.userInfo = ["title": item.title, "UUID": item.UUID]

Related

How to prevent an iOS notification being removed from the Notification Center when tapped

Is there a way to prevent a remote notification in the Notification Center from being removed by the OS after it is tapped by the user? The tap invokes the app and didReceiveNotificationResponse() is called. I am not using badges in the notifications.
Apple is not allowing to persist the notification once after you open it.
What’s next
You can create a local notification from data you get from push notification when user taps on it. I have not tried the implementation but it should work in your usecase.
User will not be knowing whether it is local or push notification.

Clear local notification with same category from notification panel, iOS

Is there any way to set time duration for a local notification to be displayed in notification panel, so that all notifications will be eventually cleared from notification panel after certain time.
You can not clear the local notifications until your app is not launched. When launched you can clear existing notifications using
UIApplication.sharedApplication().cancelAllLocalNotifications()
UIApplication.sharedApplication().cancelLocalNotification(notification)
Where notification is the notification which you want to cancel. You can persist time when local notification was persisted. On next launch based on that time you can decide whether to cancel notification or not.

Swift UILocalNotification: Is it possible to fire an event when Notification is displayed?

So I know the didReceiveLocalNotification event is fired when a user selects an action on a Local Notification.
But, is an event fired prior to that when the notification is displayed as a banner or alert when the app is not active? And can that be accessed to do some background code?
I am looking for an answer in Swift if you can help.
No, local notifications do not and cannot awake the app when firing and the application is not active. The user must tap the notification, or perform a developer defined action on it before the app hears anything.
If you need your app to wake up, you need to use a remote notification with content available flag set.

Perform action on Notification when it comes under notification tray

How to perform an action(save Unique id coming with notification, in a text file) if notification comes on Notification tray but not viewed?
Technically application delegates for notification trigger when you tap on notification in tray(open or view). you can not do anything on notification receive until any user-action on it. But when the app is in foreground applicationDidReceiveRemoteNotification automatically triggered by ios on notification receive, at that point you can do what you want. But not when your app is in background or not running.

Stack one push notification in notification center

In case the user is busy and didn't check his notifications in the notification centre. I don't want my notifications to get stacked. that may lead to removing the app. by user.
Therefore, when a notification receive I want to clear all previous notifications my app. sent and keep only the new one.
Is that possible?
Note: I want to remove them before they got clicked. If one got
clicked I can remove them easily in didReceiveRemoteNotification.

Resources