Remove remote notification from Notification Cente

2019-03-04 18:03发布

问题:

Some apps, specifically the StackExchange app and facebook are able to remove notifications from the Notification Center/Lockscreen if you view the notification elsewhere. For example if I get an inbox notification from stack exchange and then view my inbox on my laptop the notification disappears almost immediately from my phone. Originally I thought this was something just Apple could do with Mail and Facebook.

How does StackExchange send a notification to the phone to remove an existing notification?

回答1:

I think that what they do is to send a notification with a badge number of '0' to clear all the existing ones from the notification center. I have noticed the same behavior on the Gmail app, so I did some small research about it:

  • When I send one email, I receive a push notification on my phone. Then I open that email from my laptop's browser, and straight away the notification center is clear.

  • When I send two emails, I receive two push notifications. Then, when I open the first one on my laptop, both notifications still remain on my iPhone. After I open the second email (still on my laptop) the notification center gets cleared.

I did some extra checks with Wireshark and I think that every time that I open an email on my laptop, Google sends a push notification to my phone (even if there are still unread messages in my inbox).

In all the above cases, the gmail app was not running (however I'm not sure if the background fetch introduced on iOS 7 can complicate things).

I hope that helps!



回答2:

Based on @Irene's answer, my gmail-like suggestion for this would be:

As soon that happens something in Desktop or Web, i.e., you read the mail. The Google Server always calculates what is the badget/notification_number for the specific user. This is as simple as: - if it is a new mail, or marked as unread the mail, increase it - if reads, mark as read, archive or something like that, decreases. (Google only worries for mails in inbox.)

So, everytime this number changes, it sends a pushnotitfication for all sessions, updating the badget.

In the iOS case, whenever you send a badget = 0, it clears all notifications. So, in most case, if you are organized, you will receive an notification (there will only be one) and if you read it anywhere else, it will dismiss from your iOS, because you will receive badget = 1, and then badget = 0.

But as Irene mentioned, if you have more than one unread mail. it will just decrease the badget number in your app. So the gmail app icon, will decrease from 10, 9, 8, 7 ... while you are reading mails. But the same rules apply. If you get badget = 0, it will removes all local notification.

My assumption is that this does the trick.

Hope this helps,



回答3:

with Push Notifications, we can send an notification expiry (at least that is supported in PHP language) parameter and may be that is something, which updates when the email is read on another devices.

// Set the expiry value to 86400 seconds - 1440 minutes
$message->setExpiry(86400); // This message will expire in N seconds

Same happens with Viber application, it supports desktop app and iOS app, if u get any new message it sends you out the notification and as you read in your computer, it also removes the push send to mobile. This should be with expire parameter as per my knowledge.

Please correct me, if I am wrong.