iOS - Chat application with push notification

Adnan picture Adnan · Mar 6, 2014 · Viewed 9.7k times · Source

My question is simple, is it a good idea to develop chat application using push notifications? Hence push notifications are not reliable and there is no guaranty either they would arrive or not. If it is not reliable, which technique should be used for real time chat application?

Answer

Mick picture Mick · Feb 24, 2015

Why not?

It's definitely possible to build a chat using iOS push notifications. @Aaron points are interesting, but don't make sense in my opinion for the following reasons:

  1. If your app sends too many push notifications (and it will if you use that as the means of "chatting") no one will use your app because it will be annoying.

The only case here is when the app is not running and even then, apple will only send the last notification if there are too many in a row. When the app is in any other state (background, foreground active & inactive, suspended), the notification can be handled silently, using content-available : 1 in your push notification. If that's a worry for you, simply use badge notifications instead of alert notifications.

  1. The user can also disable push notifications for your app so you can't rely on that as the only means of communication.

That is wrong, that doesn't prevent notifications for being sent to the phone, they are just not being shown to the user. See here. You can therefore handle silent notifications even though the user has disabled push notifications. This is just a setting, the device will still have a device token, and the backend will still be in a position to send push notifications.

However..

It is true that some remote notifications might not be delivered and using their content is not a good idea. But that is not a big issue..

The best is to use your notification as a refresh me I got a new message kind of notification. Once you get a new notification, ask the server for new messages in this chat, and update the table. We have implemented this in one of our project and are very happy with the results so far. Some say Premature Optimization is the root of all evil, in that case, you could spend a lot of time using sockets, but you can be up and running in no time with push notifications. Optimize later.

This works great:

{
    "aps" : {
        "content-available" : 1,
        "alert" : "This is my new notification",
    }
    "conversationId": 23,
    "senderId":44
}