问题
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.
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.
When the app is in foreground and I lock the device, no notifications are triggered but messages are received perfectly.
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.
回答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.
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.
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.
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.
来源:https://stackoverflow.com/questions/35056452/xmpp-ejabberd-saas-push-notifications