Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using APNs in a messaging app

I'm working on a messaging app (something like WhatsApp) and I have a dilemma about implementing it's main functionality - sending message from client1 to client2.

The thing is I'm using a centralized server design, where clients uses NSURLConnection to send messages to the server, the server doesn't keep and manage open sockets and can't send a message for one of the clients, so clients have a timer and query the server every 2 seconds to see if a new message is waiting for them.

The problem with this approach is that querying the server every 2 second seem to kill the battery very fast, so I thought maybe instead of client querying the server, to use APNS so when client1 send a message to the server, the server will send a push notification to client2, then client2 will fetch the data from the server.

Will this approach work with a massive messaging app requiring massive push notification uses?

like image 930
Eyal Avatar asked Feb 28 '12 11:02

Eyal


People also ask

Does FCM uses APNs?

APNS channel The most common way is sending the message via APNs. If you're using the FCM v1 HTTP API to request a message delivery or if you're using the legacy FCM API to send display messages, FCM will contact APNs to deliver the notification.

Why you use FCM notification instead of APNs?

APNs and WNS do not support multiple platforms. They are designed to work with their native platforms. But, FCM supports multiple platforms such as Android and iOS and even supports Chrome web apps.

What is the use of APNs?

Apple Push Notification service (APNs) is a cloud service that allows approved third-party apps installed on Apple devices to send push notifications from a remote server to users over a secure connection. For example, a newstand app might use APNs to send a text alert to an iPhone user about a breaking news story.

Can you send push notifications without an app?

Pushed allows you to send real-time notifications without developing your own app to iOs, Android and Desktop devices.


1 Answers

Yes. I would say this approach is okay and will perform well.

You could also create a socket connection when your application is running in front. But the APNS-way (your preferred way) will also work when the user has quit your app.

APNS can handle huge load. There where only very few delays as far as i noticed.

The PUSH-System on iOS is just a HTTP Connection to apple which keeps the response-channel open for some hours (like loading a webpage for some hours). It will use around +10% of your battery. So best would be to not create another keep-alive HTTP/Socket connection and to re-use apples channel (APNS) to save the endusers battery.

In your app you will receive the Push-Notification and you can parse the JSON-Data and then pull/sync with your own server.

You should also take in mind what to do, when your app is not running in foreground (then you might display the received message as APNS messages as WhatsApp does).

like image 99
Jonas Schnelli Avatar answered Sep 23 '22 15:09

Jonas Schnelli