Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a local notification in iPhone

Tags:

iphone

I am making an application that sets a local notification.

Thankfully I was able to set the local notification but I don't know how to delete the notification which is set by my application.

The XCode does provide functionality of delete with removeAllNotifications but you cannot remove specific notifications set by the application.

Thanks a lot.

like image 551
Aditya Kaushik Avatar asked Jul 30 '10 14:07

Aditya Kaushik


People also ask

What is local notification in iOS?

Use local notifications to get the user's attention. You can display an alert, play a sound, or badge your app's icon. For example, a background app could ask the system to display an alert when your app finishes a particular task. Always use local notifications to convey important information that the user wants.

How many local notification are there in iOS?

But in iOS we can't schedule more than 64 notifications at a time.

How do you delete a notification request in Swift?

To remove all pending notification requests use the removeAllPendingNotificationRequests() method.


2 Answers

You asked this question twice, so I'm answering on both questions in the hopes of it reaching you:

Cancel all local notifications with this code:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

Cancel one local notification with this line of code:

[[UIApplication sharedApplication] cancelLocalNotification:theNotification];

where theNotification is a UILocalNotification object, so in order to cancel a specific notification you need to hold on to it's UILocalNotification.


You can find more stuff in apple's documentation.

like image 100
winsmith Avatar answered Oct 11 '22 02:10

winsmith


[[UIApplication sharedApplication] cancelLocalNotification:notification]
like image 28
Paulo Casaretto Avatar answered Oct 11 '22 03:10

Paulo Casaretto