当设备在 ios 中连接回互联网时获取所有通知 [英] Get all the notification when device connect back to the internet in ios

查看:15
本文介绍了当设备在 ios 中连接回互联网时获取所有通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在objective-c中开发了一个iOS聊天应用,当用户A向用户B发送消息时,用户B收到推送通知.当 UserB 收到推送通知时,它会向我的后端调用一个 url,以了解 UserA 您的消息已发送给 UserB(当应用程序未运行或被终止时).这一切都很好,反之亦然.

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.

但我的问题是,当用户 A 向用户 B 发送超过 5-10 条消息并且用户 B 未连接到互联网时(我的后端也向用户 B 发送成功消息 - 通过 FCM).当用户 B 连接到互联网后,它只收到最近的通知.

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.

这是因为苹果在维护 QoS.我读了 这篇 文章.

This is because apple is maintaining QoS. I read this article.

所以为了解决这个问题,我尝试在发送请求以通过 fcm 发送推送通知时添加 apns-collapse-id 参数.但这一次最多只能结合 4 个通知.此外,这种情况并非一直有效.有时只收到 1 条消息,而不是全部.

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.

简而言之,我想在连接到互联网时显示与 Whatsapp 显示所有通知相同的所有消息通知.

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.

推荐答案

在这种情况下你能做的是,

What you can do in this case is,

  1. 从 APNS 中删除所有待处理的通知.

[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];

  1. 调用服务并从您的服务器中为特定用户提取所有通知.
  2. 当您收到来自服务器的响应时,在您的应用中显示本地通知.
  3. 同时通知您的服务器您已显示的所有通知,并将它们标记为已在您的服务器上发送.以便下次您可以收到所有尚未发送的通知.

这篇关于当设备在 ios 中连接回互联网时获取所有通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆