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?
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.
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.
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.
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:
- 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.
- 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.
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
}
No. It is not a good idea, for at least two reasons:
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With