Apple Multiple Push Notifications not visible in Notifications Tray

早过忘川 提交于 2019-12-04 08:42:38

问题


I basically want to make multiple push notifications in the same application visible in the notification tray in iOS.

This scenario works if my data is on while push notification is triggered via APNS, but only the latest one is received in case I am offline and come back after a while. This functionality is affirmed by APNS documentaion.

However, this is what worked in WhatsApp:

  1. Turned Data Connection OFF
  2. Sent some messages to WhatsApp
  3. Turned Data Connection ON
  4. Saw multiple push notifications received in Apple's Notification Tray

How's this scenario working? Can I use APNS for this? If yes, then how?

See this sample image of multiple Push Notifications in WeChat.


回答1:


Like you wrote in your question, this is mentioned in the Apple Docs:

If you are sending multiple notifications to the same device or computer within a short period of time, the push service will send only the last one.

Link

The only scenario that what you're describing will work is if your whatsApp was open in the background while getting those push notifications. That way whatsApp will handle them as local notifications and will present all of them in the notification center. If whatsApp was closed you'd get only the last notification like any other app.

You can easily test this:

  1. Terminate whatsApp and turn on Airplane mode.
  2. Send your device 5 messages from 1 to 5.
  3. Turn Airplane mode off and lock your device.
  4. You'll only see one msg (the last one you sent aka "5") in your notifications center.

This is how whatsApp is making it work:

While whatsApp is in the background, a single push notification is received (the last one the user sent, "5" in our example). That msg will not be shown to the user.

whatsApp receives it in the method application:didReceiveRemoteNotification:fetchCompletionHandler: and checks against their servers if there are any notifications prior to "5" that the user didn't receive. If that's the case, they will pull that data from their servers and will present it to the user using local notifications which is basically just a way to present data and not related to APNS at all.




回答2:


It is explained in Troubleshooting Push Notifications. Check for "Some Notifications Received, but Not All" section.




回答3:


As described you cannot have any control over those push notifications.

However you may know that from iOS7 a new background execution mode (remote-notification) allows the App to be awaken by the system when a push is received, allowing you to process some data, then go back to sleep...

This is probably the trick: using that way to receive the push notifications (silently) and then trigger your own local notification instead as @Segev said. See the UIBackgroundModes here.



来源:https://stackoverflow.com/questions/28502268/apple-multiple-push-notifications-not-visible-in-notifications-tray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!