1

It could be a possible duplicate link of.

Remove single remote notification from Notification Center

According to this post we can't delete single notification from notification center(NC). For canceling notification we have below methods.

1).cancelAllLocalNotifications : it remove all notification. 2).cancelLocalNotification : it require notification as input.

I tried both methods, using first one it remove all notification from NC and the second one not seems work. Here is the second snippet which I am applying on didRecivedRemoteNoitification method.

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;
    NSLog(@"userInfoCurrent : %@", userInfoCurrent);
    int notiid=[[userInfoCurrent valueForKey:@"notificationID"] intValue];
    if (notiid ==deletenotiid)
    {
        //Cancelling local notification
        [app cancelLocalNotification:oneEvent];
        break;
    }
}

So my question is I am seeing couple of application that remove the tapped one notification from NC for example skype

Is there something which I am missing to apply.

Thanks for your valuable time.

Community
  • 1
  • 1
Himanshu Ingole
  • 55
  • 2
  • 11
  • You can only cancel local notifications, not remote ones (because local ones are scheduled and you can therefore cancel them before they launch). – Graham Jun 02 '13 at 16:41
  • ACtually I am looking for remote push notification; In the given post the mentioned one solution which remove all notification however, my requirement is to remove only tapped one. – Himanshu Ingole Jun 02 '13 at 18:11

1 Answers1

0

You wrote that you included the above code in didRecivedRemoteNoitification. However, didRecivedRemoteNoitification is called only when a push notification arrives while the app is running in the foreground, in which case no notification is displayed and there is nothing to clear.

For notifications that arrive while the app is not running, when a user taps the notification, the notification data is passed to application:didFinishLaunchingWithOptions:. I think the tapped notification will be cleared if you clear the badge number.

- (void)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts {

    // check launchOptions for notification payload and custom data, set UI context

    [self startDownloadingDataFromProvider];  // custom method

    app.applicationIconBadgeNumber = 0;

    // other setup tasks here....

}
Eran
  • 387,369
  • 54
  • 702
  • 768
  • Thanks Eran for answering but I already tried this solutions using mentioned solution it remove all notification from center not the tapped one. – Himanshu Ingole Jun 03 '13 at 13:33
  • Is there any possibility to remove single notification? – Himanshu Ingole Jun 15 '13 at 15:19
  • Unfortunately not. In the current iOS SDK, you can't remove just a single notification from the Notification Center programatically. I wonder why apple don't care about these basic issues. Android is way good in handling push notifications. – Diego Palomar Apr 01 '14 at 09:03