Pregunta

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?

¿Fue útil?

Solución

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).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top