10

My app daily broadcasts a Push Notification (PN) to all users which becomes irrelevant after 4 hours. Is there any way I can remove that notification on every user's notification centre that has not tapped it within those 4 hours?

I used to think this is not possible yet, but became hopeful after seeing the Google's Hangout app behaviour - It sends PN to Mac & iOS... and if I read the message on Mac, it automatically immediately removes it from iOS' Notification Center.

I did extensive research on google, surprisingly found nothing on this - just one question here which has been duly closed!

2
  • 3
    As far as I know, I don't think it is possible. The user has to tap on that in order to remove the badge.
    – Ricky
    Commented May 6, 2014 at 8:03
  • 2
    @voyage11 - but I see Goggle Hangout app doing that.. when I read a message on Mac, the iOS notification centre removes the notification. I have edited the question to mention this. Commented May 6, 2014 at 8:08

2 Answers 2

11

The trick is to make your app support background fetching and handle the push notification when you app is in the background.

Then in the application:didReceiveRemoteNotification:fetchCompletionHandler: set the application badge to 0 so that all you push notification are removed from the notification center.

Send a special push notification where there is not data displayed to user but does contain a an command to reset the push notification state.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

  if([[userInfo objectForKey:@"reset"] boolValue]){
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
  }

}
4
  • However, as it requires app to be in background... which is not the case here & also this will dismiss other imp PNs as well, I am skipping it & will wait for Apple's proper way (if any). However, answer can be useful for others. +1'd. Thanks again. Commented May 6, 2014 at 8:41
  • Well you could just remove the push notification and add local notification for the push notification that you want to keep. Since this method allows you to communicate with your server you could even do everything with local notifications.
    – rckoenes
    Commented May 6, 2014 at 8:53
  • @rckoenes will this only remove remote notifications and not local notifications?
    – Naddy
    Commented May 11, 2016 at 17:12
  • That might be the case, but you could easily remove the local notification as well
    – rckoenes
    Commented May 11, 2016 at 19:18
-5

It is only possible to dismiss a notification once the user has tapped. You can't dismiss on hide it if the user hasn't tapped it to open.

If you want to dismiss an opened notification, you can try cancelLocalNotification: to dismiss a notification that is presenting an alert at present. According to apple documentation: You can cancel a specific scheduled notification by calling cancelLocalNotification: on the application object, and you can cancel all scheduled notifications by calling cancelAllLocalNotifications. Both of these methods also programmatically dismiss a currently displayed notification alert.

1
  • 4
    cancelLocalNotification: and cancelAllLocalNotifications will not work for push notifications only for local notifications.
    – rckoenes
    Commented May 6, 2014 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.