我们正在为我们的移动聊天应用程序使用 ejabberd 服务器。 我们正在为我们的 IOS 应用程序使用 IOS XMPP-Framework (https://github.com/robbiehanson/XMPPFramework)
但是我们在实现过程中遇到了一个问题,我们找不到解决方案。 我们已经实现了 XMPP 消息传递的各个方面,并且除了一件事之外一切都很好:
当我们的应用程序处于后台时,我们的 ejabberd 服务器会向我们发送推送通知,以通知我们有关离线消息的信息。 (仅发送离线消息通知)
然后我们决定实现 IOS 后台推送通知功能,以便在应用程序处于后台时获取离线消息。
但问题是我们必须在线(发送出席信息)才能获得离线消息。 但是当我们这样做时,它会产生 2 个不良后果:
为了解决这个问题,我能想到的唯一一件事是,如果有一种方法可以从 xmpp 服务器检索离线消息而无需在线。 有谁知道是否有任何方法可以使用 XMPP-Framework for ios 来做到这一点
[编辑] 让我再澄清一下这个问题:
问题不止一个:
问题 1 - 推送通知问题:
1.1 - Server check if the message is sending to an online or offline user. If the user is offline server sends push notification to inform user but if the user is online server doesnt send anything.
1.2 - When the application is in background and receive notification for offline messages, application become alive(still in background) and become online in order to get offline messages
1.3 - Because the client became online, server doesnt send the push notifications anymore but the application is still in background so the user cannot be informed about the message he/she received.
所以为了解决这些问题,我需要找到一种方法来通过不将在线状态发送到服务器来接收离线消息
问题 2 - 消息接收问题
2.1 - Server check if the message is sending to an online or offline user. If the user is offline server sends push notification to inform user but if the user is online server doesnt send anything.
2.2 - When the application is in background and receive notification for offline messages, application become alive(still in background) and become online in order to get offline messages
2.3 - When the application became online server sends all offline messages to client but doesnt send the total count of offline messages(At least I cannot get it with IOS XMPPFramework)
2.4 - So I dont know how much longer the client should stay alive in the background because I dont know the total count of offline messages, so after getting 2-3 messages I have to suspend the application in the background. But in that case there might be buggy situations such as XMPP Framework receive the offline message but I suspend the client application before writing it to database etc...
为了找到解决这些问题的方法:
这个想法是当用户下线时:
[已编辑]:
我在 16.06 上使用它。源代码中出现错误:
...
Body = xml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),
...
Type = xml:get_tag_attr_s(list_to_binary("type"), Packet),
Body = xml:get_path_s(Packet, [{elem, list_to_binary("body")}, cdata]),
...
我通过将 f
添加到 xml:
来修复它们,例如
正文 = fxml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),
对于 MUC,离线用户位于“离线”字段中,格式为“user1..user2..user3..”,您需要将它们从字符串中拆分出来。
关于ios - 从 XMPP 获取离线消息而不变为在线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40441055/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |