Currently I have an IOS chat app that runs with firebase. The app is working fine and sending and receiving messages when two users are online. I am using real-time database, however when one of the user is offline (i.e application is killed or even the app is running in background) and the other user is sending a message the messages are not received. Is there is a way where can I know the current state of the user and instead of sending the message I send a notification to notify him that there is a new message.
Related
I have implemented chat application using firebase realtime database and it working fine. I have few more requirements to meet the complete functionality. Below is the requirement
Last entered message with date/time
No. of Unread message
While you are in the chat listing page showing or updating the counter with messages spontaneously when someone is sending you message
Sending push notification when a user send message
Is these possible using the firebase functionalities ?
When the app is in background and receive a data message, the delivery of the data message is delayed and the app will receive this message when it's will become foreground via messagingDidReceiveMessage. When the app is foreground then it's will receive the data message directly on messagingDidReceiveMessage
My problem: how to know in messagingDidReceiveMessage that the data message was received when the app was in background and was waiting the app go foreground ?
messagingDidReceiveMessage is used to receive messages that bypass APNs and are sent directly to your app from FCM. This is only available when a connection is open between your app and FCM, this is only available when the app is in the foreground.
To receive data messages when your app is in the background you need to use the APNs callbacks. You can still send data messages through FCM when your app is in the background but you can't use the messagingDidReceiveMessage callback in that case.
When sending a message with both data and notification payload set, they are displayed as usual when the app is in background. However, when the app is in foreground, they are received in
UNUserNotificationCenterDelegate userNotificationCenter:willPresentNotification:withCompletionHandler:
This works fine so far, but the delay between sending and receiving foreground messages is considerably higher than the one we observed on our android application (which also uses Firebase). The reason seems to be that these notifications are always sent via APNS instead of the persistent Firebase connection.
How can I force Firebase to send messages containing both data and notification payloads via their own connection instead of APNS when the app is in foreground?
So basically I want them to behave like pure data messages (which are received in IRMessagingDelegate applicationReceivedRemoteMessage:) when the app is in foreground and still be able to display a notification if it's not.
Unfortunately, you can't. If there's a notification element attached to the message, FCM will always send those through APNs.
Your only option might be to send two messages -- one data only message (which will be sent via FCM when your app is in the foreground) and a notification message (which will be sent via APNs), and have your app handle the case of it receiving both of these messages if its running in the foreground.
I am working on a chat using XMPP Protocol. Everything is working fine using XMPP. But I'm unable to receive offline messages from agent when user comes to online. As user A is logged out and user B sends messages to user A, and when user A logs into app, it must receive all the messages that were sent by user B during offline session. How can I receive these messages?
With rooms you can do this easily by joining the chat asking history since the time you went offline. For one-to-one chat, you will have to implement per user offline queue at the server end. And notify server once you are online to receive the chats.
I have an instant messaging app in iOS. I want to use push notification to let the user know if he has received a message while the app is minimized.
Initially i ve implemented the app such that when the app is minimized, the app informs my server which in turn contacts the APNS to inform that a message is received.But there is a delay for the app to inform the server. Hence if the user minimizes the app and , at the same time a message is being sent to him, he does not get the notification since my server is still sending the message to the app and not the APNS.
I am wondering how this scenario is overcome in chat apps. Are they sending all chat messages to APNS irrespective of whether the user has minimized the app or not. If i send all messages to APNS will that be a good design?
On iOS, you can't rely on any processes that are working when the app is "minimized" (actually in background). Your process can be killed by the OS for a variety of reasons and in any case, unless you qualify for exceptional extended background processing, your app can not process for more than 10 minutes.
Typically, for a chat-type app, every time a message is received by a client, the same client sends back a message to let the server know that it has received said message. This way, if your server doesn't get a signal that the message was received after a few seconds, you can assume that the app is not running on the device and can send the message via push instead.
There is no need to use excessive processing on the client which will drain the battery and there is no need to send a push for every single message.