2

I recently ran into a problem on my instant messaging app. I am using Ejabberd 17.04 with mod_stream_management and mod_offline enabled and XMPPFramework on iOS. And I have a hard time on closing the connection and terminating the stream with </stream:stream> while the app is going to background.

Here is the current situation, I wish to send Push Notification while the client is in the background and use my Ejabberd server while in the foreground.

When the client is going to background I do the following in func applicationDidEnterBackground(_ application: UIApplication).

  1. Send presence unavailable with <presence type="unavailable"/>
  2. Invoke XMPPStream.disconnectAfterSending() to send </stream:stream> and also disconnect from Ejabberd server. By doing this, I suppose that the stream will be terminated and disconnected.

By receiving the unavailable presence, the server will send all messages to offline message and send Push Notification.

Unfortunately, the result is not, the stream might sometime not being terminated and the user presence stays available. In that case, Ejabberd is not aware of the new state (unavailable) of the client and continue to send messages to the old stream instead of sending Push Notification which causes message loss.

I set the timeout of the stream to 5 minutes and should resend the "lost" messages to the client. But I find that the delay is unacceptable and also not what I am expecting.

I wonder if there is a way that I could make sure the stream is terminated properly and set the presence to unavailable at the same time, so I can send Push Notification correctly. I could provide more details if necessary. Thanks.

Vincent Lam
  • 151
  • 2
  • 2
  • 10

0 Answers0