2

My app has notification feature. When I receive a notification I show a badge in my app icon.

As I know, when my app is on background, since user does not clicks on the notification at notification center, my app does not know that it has a notification. So it can not change the badge number.

Also from this topic: Detect when a user clears notification from the notification center

If user clears the app's notification, the app can not detect it.

So the problem is here:
- My app is on background
- User receives a notification related to the app
- App adds a badge with number 1 to the app's icon
- User deletes the notification from notification center
- App never understands that notification has been removed so that it can remove the badge!!!

So how other apps fix this problem? Is there any solution for this?

Community
  • 1
  • 1
Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115
  • 1
    There is no way to check whether user deleted the notifications or not. – Ritu May 19 '15 at 09:30
  • so how can I remove the badge when user clear the notification from notification center, how other apps do this? maybe my mechanism is bad – Husein Behboudi Rad May 19 '15 at 09:32
  • 1
    Can you provide the name of app which clears the badge number even app is in background – Ritu May 19 '15 at 09:35
  • when the user deletes a notification from Notification Center it does not mean your application has handled the notification at all – it means the user does not want to see your notification in the Notification Center, but your app still has a new notification; don't need to mix these two things together. – holex May 19 '15 at 09:41
  • @holex as I know untill user do not click on the notification at notification center, I can not read the content of the notification. So when user remove it from notification center how can I get its content? – Husein Behboudi Rad May 19 '15 at 09:48
  • @HuseinBehbudiRad ***you should not be relying on the user tapping on your notifications in order to get their content.*** See my answer for details. – Greg May 19 '15 at 09:53
  • 1
    when the user removes a notification from the Notification Center is outside of the actual application's scope; meanwhile the user sees the notification (if the text is long, they see partially only) and without interacting with the notification they can remove it – that scenario is not equal to when you handle the notification inside your app as _deleting_ a notification is not equal to _activating_ it. – holex May 19 '15 at 09:55

2 Answers2

5

There is no way to check when the user clears notifications for your app.

The usual practice for clearing the app badge is when the user has viewed the applicable content within your app (e.g. messages in a messaging app), or otherwise just clearing the badge the next time the user opens your app if this is not applicable, or you can't easily segment the notifications and connect them to viewable content in your app.

Note: you should not be relying on the user tapping on your notifications in order to get their content. If your user doesn't tap your notification, your app has no way of ever finding out its content, or that it ever existed.

Instead, when your app is opened, it should connect to your server to download updated content, then you can use this complete, accurate information to update your app badge as required. Do not try to fetch content from your notifications.

Greg
  • 9,068
  • 6
  • 49
  • 91
  • As I know when the app is on the background, until user click on the notification I can not get the content of them. So When my user goes to my messaging page I am not believe that the app has any unread notifications or not; so if I set badge count to zero and the user has some notifications in notification bar it do not make sense – Husein Behboudi Rad May 19 '15 at 09:37
  • @HuseinBehbudiRad you can set it to 0 temporarily until you can load the content and determine what the badge should actually be, then update it. – Greg May 19 '15 at 09:39
  • It is good idea, may you please specify how can I make sure that what the badge number should be? so that I can update it? thanks. – Husein Behboudi Rad May 19 '15 at 09:42
  • @HuseinBehbudiRad that depends on how your app works. If you have a method of determining what *new* content the user hasn't seen yet after the app is opened, use it. Otherwise, just set the badge to zero. – Greg May 19 '15 at 09:43
  • Is it possible to set badge to zero but the notification remains on the notification center? – Husein Behboudi Rad May 19 '15 at 10:15
  • @HuseinBehbudiRad setting the badge to zero won't clear the notifications from notification centre. The user has to do that manually. You have no control over when they are removed. – Greg May 19 '15 at 10:16
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78170/discussion-between-husein-behbudirad-and-partiallyfinite). – Husein Behboudi Rad May 19 '15 at 10:18
  • @PartiallyFinite i work. i have up voted for it. Thanks – Ashok Londhe May 19 '15 at 10:33
1

You can add custom action to your notification: "Mark as read" or "Delete". Remove badge in -application:handleActionWithIdentifier:... method.

Yes, it doesn't allow you to detect user cleans the notification. But there is no any way to do it. So I suggest a workaround to solve this problem.

kelin
  • 11,323
  • 6
  • 67
  • 104
  • This doesn't handle the case where the user clears all app notifications using the system clear button, which is what the question is asking about. Most users will never notice that you added a special delete button, and will clear it with the system clear button anyway, so this answer doesn't help. – Greg May 19 '15 at 10:43
  • Yes, it doesn't do exactly what author wants, but then what does? – kelin May 19 '15 at 12:22