0

I have some repeated actionable notifications, and when I tapped on button of some notification (I mean this), I have to delete all the same notifications. For example, I have 4 already pushed notifications:

Not 1
Not 2
Not 1
Not 2

If I use actions of "Not 1", I need to delete all "Not 1", so, It will be like this

Not 2
Not 2

Can I do this?

[UIApplication sharedApplication].scheduledLocalNotifications]

gives me only scheduled notifications, but I need to delete already showed notifications, whitch isn't in this array.

AntiVIRUZ
  • 342
  • 1
  • 14
  • So what do you get when you log the array returned from the app? – Wain Jan 13 '16 at 07:46
  • look at this, possible duplicate question http://stackoverflow.com/a/6341476/4582941 – Massimo Polimeni Jan 13 '16 at 09:26
  • @Wain for example, if I plan 3 notifications: first, second and third; first and second has been already pushed, and third only will be, scheduledLocalNotifications will be contained only third. – AntiVIRUZ Jan 13 '16 at 10:10
  • 1
    Possible duplicate of [Delete a particular local notification](http://stackoverflow.com/questions/6340664/delete-a-particular-local-notification) – Baris Akar Jan 13 '16 at 12:08

1 Answers1

0

You can save a unique value for key in your local notification's userinfo. Get all local notification, loop through the array and delete the particular notification.

Code as follows,

UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
    UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
    NSDictionary *userInfoCurrent = oneEvent.userInfo;
    NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"uid"]];
    if ([uid isEqualToString:uidtodelete])
    {
        //Cancelling local notification
        [app cancelLocalNotification:oneEvent];
        break;
    }
}
Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
vibhor
  • 111
  • 6
  • '[UIApplication sharedApplication].scheduledLocalNotifications]' gives me only scheduled notifications, but there isn't already showed ones. – AntiVIRUZ Jan 13 '16 at 10:06