Using APNs in a messaging app
Asked Answered
B

1

7

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?

Benoite answered 28/2, 2012 at 11:26 Comment(0)
F
5

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

Floruit answered 28/2, 2012 at 11:47 Comment(2)
"But the APNS-way (your preferred way) will also work when the user has quit your app" - Either way I was planning to use the APNS when the user is offline. My main concern is: 1. Is APNS relabel enough that I can use it as my core messaging mechanism. 2. Will apple approve potentially thousands or hundreds of thousands push notification a day from my server?Benoite
1. If you don't break the apple "law" (no spam, no ad-stuff), then yes. WhatApp and co. also relies on APNS. And theres no other way to do that when you like to receive messages in "non-app-foreground" mode. 2. Yes. They won't reject the app because of high load on the APNS (except the content in your push messages is invalid from apples perspective [spam, ads, etc.])Floruit

© 2022 - 2024 — McMap. All rights reserved.