Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Chat application with push notification

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?

like image 740
Adnan Avatar asked Mar 06 '14 18:03

Adnan


People also ask

Does iOS support push notification?

Apple has been supporting push notifications on OS X via the Apple Push Notification Service (APNS). Developers also use APNS to deliver a notification to iOS devices.

What is a chat push notification?

Push notifications are messages which can be sent directly to a user's mobile device, and which appears on screen, or in the top section of a mobile device.

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.


2 Answers

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
}
like image 86
Mick Avatar answered Oct 23 '22 08:10

Mick


No. It is not a good idea, for at least two 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.
  2. The user can also disable push notifications for your app so you can't rely on that as the only means of communication.

You want a polling system of some sort with a client/channel relationship. There are lots of server systems out there that can do this for you. WebSync is one:

http://www.frozenmountain.com/websync/

like image 31
Aaron Avatar answered Oct 23 '22 06:10

Aaron