0

I am pushing some text to an iPhone app. once the message is accepted and processed in the app I still see the message in the notification area and if I accept it again the message get duplicated in the app.

how I can avoid that? Is there away to remove it from the notification area once the push is accepted.

In other words, once

- (void)application:(UIApplication *)application
      didReceiveRemoteNotification:(NSDictionary *)userInfo 

is executed, I want to remove the notification from the notification area.

Kara
  • 6,115
  • 16
  • 50
  • 57
shebelaw
  • 3,992
  • 6
  • 35
  • 48
  • is it a local or remote notification? – Saurabh Passolia Feb 12 '12 at 07:22
  • See this answer: http://stackoverflow.com/a/7821985/428442 . The trick, apparently, is that the app badge value has to change. So set it to 1 and then to 0, and that is supposed to remove the notification from the notification center. – Mark Granoff Feb 13 '12 at 19:42
  • it looks the link you provided talks about local notification. I am looking for removing Remote notifications. and I am not using bag number. – – shebelaw Feb 13 '12 at 21:44

2 Answers2

7

Setting the badge value to 1 or some value first then set it back to 0 worked. Like the following:

  [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  [[UIApplication sharedApplication] cancelAllLocalNotifications];
shebelaw
  • 3,992
  • 6
  • 35
  • 48
  • @shebelaw Above code will help to remove all the notification from notification center. But is there any way to remove single notification which we have selected from notification center. – Hrushikesh Betai Aug 09 '13 at 10:59
1

Try this maybe?

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
mbh
  • 3,302
  • 2
  • 22
  • 24
  • I set this just before `- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo` completes. – shebelaw Mar 04 '12 at 23:39