问题
I have developed one iOS chat app in objective-c, in which when UserA send message to UserB at that time UserB get push notification. When UserB get push notification it is calling one url to my backend to know UserA that your message is delivered to UserB(when app is not running or killed). This all working fine visa-versa.
But my problem is that when UserA sends more than 5-10 message to UserB and UserB is not connected to the internet(my backend is also sending successful message to UserB - via FCM). After when UserB connect to the internet its receiving only most recent notification.
This is because apple is maintaining QoS. I read this article.
So to solve this issue I tried to add apns-collapse-id parameter when sending request to send push notification via fcm. But this is combining only max 4 notification at a time. Also this scenario not working all time. Sometimes getting only 1 message not all.
In short I want to display all the message notification same as Whatsapp displaying all notification when connect to the internet.
Please guide me what to do now to solve this issue. Thanks in advance.
回答1:
What you can do in this case is,
- Remove all the pending notifications from APNS.
[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
- Call a service and Pull all the notifications from your server for particular user.
- When you receive the response from your server, show local notifications in your app.
- Also notify your server which all notifications you have displayed, and mark them delivered on your server. So that next time you can get all the notifications that are not delivered yet.
来源:https://stackoverflow.com/questions/50599054/get-all-the-notification-when-device-connect-back-to-the-internet-in-ios