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

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

问题描述

我已经在Objective-C中开发了一个iOS聊天应用程序,其中,当UserA当时向UserB发送消息时,UserB会收到推送通知.当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.

但是我的问题是,当UserA向UserB发送超过5-10条消息并且UserB未连接到Internet时(我的后端也通过FCM向UserB发送了成功消息).当UserB连接到Internet后,它仅接收最新的通知.

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天全站免登陆