0

This is an update to my previous question, XMPP push notifications causing problems.

Thanks to the answer from Mickaël Rémond delay and duplication issues are gone but I still fail to understand the behaviour of push notifications.

  1. If I move the app to background (without locking device or termination) it won't receive any push notifications, and when I bring it back to foreground all the messages are received perfectly.

  2. When the app is in foreground and I lock the device, no notifications are triggered but messages are received perfectly.

  3. When the app is in background and I lock the device, notifications are triggered, messages are received perfectly but sometimes messages are received after sending sendLastActivityQueryToJID.

I don't know what's going on here but if you guys have any idea please let me know.
PS i have removed Background modes form my app.

Community
  • 1
  • 1
iYousafzai
  • 1,021
  • 1
  • 10
  • 29

1 Answers1

1

It does not seem to have anything to do with ejabberd but seems related to how push notification works on iOS.

I am not totally sure what you are trying to do but you should not remove background mode for your app. There is no need to and there is many other benefit in allowing the app to run for a short while in background mode, to do proper house keeping tasks.

  1. App in background usually run for three minutes before being killed. It means during that time you receive normal XMPP message inside the app. You have to trigger local notification from the appm in that state and upon receiving an XMPP message.

  2. When app is in foreground, iOS will never display any notification. This is expected. If you are connected on the XMPP server, you will receive XMPP message. If not connected, you will receive notification, but they will not be displayed. It is up to you to do something with them in your app.

  3. You have some confusion in your question: If you app is in background, notifications are trigger, but message should not be receive at the same time only when you reopen / reattach to session or reconnect. If you need some traffic to receive messages, it is because you are not doing whitespace keep alive. If you do not do that, the server will think you suddenly lost the connection and will start sending push notification and buffering messages. Make sure you implement whitespace keep-alive as recommended in the document as otherwise it cannot work fine.

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
  • I have handled everything properly for local(background modes enabled) and push notifications.The problem was/is with session rebind.i am doing proper whitespace keep alive.If stream is disconnected i send connect with timeout but it is creating a new session and session reestablishment by sending rebind stanza after receiving stream features is Session not found. – iYousafzai Jan 29 '16 at 17:12
  • You are probably using the wrong session ID. You need to always store the one on the last stream open received during the previous session, not the first one received. – Mickaël Rémond Jan 29 '16 at 18:31
  • Here is a log of user's connection flow http://pastebin.com/vd9XCtcc . Which session should i be storing after connection or authentication? And when should i send the rebind stanza after connection or authentication? I have tried everything but still no luck.Thanks – iYousafzai Jan 30 '16 at 22:06
  • As I said, you need to used the last stream if receive. Always store and resend the last stream id and you will be fine. – Mickaël Rémond Jan 30 '16 at 22:13
  • In the logs there are two ids.one after connection and one after authentication.And i should send the rebind stanza after connection right? – iYousafzai Jan 30 '16 at 22:16
  • @MickaëlRémond How to send white space, from mobile client. Here in [link](https://ejabberd-saas.com/Mobile_XMPP_Stack.pdf) this say .._client to send neutral "\n" or "\r\n" characters between stanzas_ ..but how to do that. Please suggest. – CoDe Jul 25 '16 at 10:31
  • You need to modify your library to support that. This is generally not supported by existing libraries. – Mickaël Rémond Jul 25 '16 at 17:36
  • Do I need to send it manual. Let me know if do you have any reference code!! – CoDe Jul 27 '16 at 06:25