从XMPP获取离线消息而不在线

我们正在使用ejabberd服务器为我们的移动聊天应用程序。 我们正在为我们的IOS应用程序使用IOS XMPP-Framework( https://github.com/robbiehanson/XMPPFramework )

但是我们在执行上遇到问题,我们找不到解决scheme。 我们已经实现了XMPP消息传递的各个方面,除了一件事之外,

虽然我们的应用程序是在后台,我们的ejabberd服务器向我们发送推送通知,通知我们关于离线消息。 (只发送离线消息的通知)

然后,我们决定实施IOS背景推送通知function,以在应用程序处于后台时获取脱机消息。

但问题是我们必须成为在线(发送状态)才能获得离线消息。 但是当我们这样做时,会产生两个不希望的后果:

  1. 发送消息的一方看到我们作为在线(尽pipe我们在后台)
  2. 由于我们在应用程序处于后台时正在联机,因为我们在线并且服务器只能发送离线消息的通知,所以我们的服务器无法发送其他人的消息的推送通知。

为了解决这个问题,只有我能想到的是,如果有办法从xmpp服务器上检索离线消息而不上网。 有谁知道是否有任何方式与XMPP框架的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. 

所以为了解决这些问题,我需要find一种方法来接收离线消息不发送在线状态到服务器

问题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... 

为了find解决这些问题的方法:

  1. 我需要find一种方法,当我想从服务器获得只有1离线消息
  2. 如果可能的话,我也需要得到这些离线消息,而不会上网

看看ejabberd_mod_offline_post

  1. 首先configuration房间必须是仅限会员的房间,并在创build后立即添加所有用户作为成员,以便能够获得总计。
  2. 将上面的模块添加到ejabberd模块中。
  3. 实现callback服务来处理callbackpost。

这个想法是当用户离线时:

  • 在一对一的情况下,将会引发offline_message_hook
  • 在MUC的情况下,会产生muc_filter_message,任何一个非Presence-Available离线。

[编辑]:

我在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:来修复它们,例如Body = f xml:get_path_s(Stanza,[{elem,list_to_binary(“body”)},cdata]),

而对于MUC来说,离线用户在“离线”字段中的格式为“user1..user2..user3 ..”,您需要将其从string中分离出来。

例如,我build议您为自己的“后台”在线状态添加一个自定义扩展元素

 <presence ...> <source xmlns:="com.foo#background"/> </presence> 

那么,在客户端,当您收到状态时,不要通知扩展元素“ sourcecom.foo#background存在xmlns“ com.foo#background ”。