We are using ejabberd server for our mobile chat application. And we are using IOS XMPP-Framework for our IOS application ( https://github.com/robbiehanson/XMPPFramework)
But we have a problem on implementation that we couldn't find a solution. We've implemented every aspect of XMPP messaging and all works good besides one thing:
While our application is on background, our ejabberd server sends us push notifications to inform us about offline messages. (Only sends notification for offline messages)
Then we've decided to implement the IOS background push notification functionality to get offline messages while the application is on background.
But the problem is we have to become online(send presence) in order to get offline messages. But when we do that it creates 2 unwanted consequences:
For solving that problem, only thing that I can think of is, if there is a way to retrieve offline messages from xmpp server without becoming online. Does anyone know if Is there any way to do that with XMPP-Framework for ios
[EDIT] Let me clarify the issue a little bit more:
Problems are more than just one:
Problem 1 - Push notification problem:
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.
So In order to fix those problem I need to find a way to receive offline messages by not sending the online presence to server
Problem 2 - Message Receive Problem
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...
In order to find a solution to those problems:
Look into ejabberd_mod_offline_post
The idea is when User go offline:
[Edited]:
I was using it on 16.06. And there was an error in the source code at lines:
...
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]),
...
I fixed them by adding f
to xml:
, e.g.
Body = fxml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),
And for MUC, the offline users is in the 'Offline' field as this format, 'user1..user2..user3..', what you need to do it to split them out from the string.