Should I update my app upon receiving payload? Or I should always update it by allowing it to download for itself?
Asked Answered
E

1

5

When your iPhone receives a WhatsApp/Telegram push notification e.g.

wife:
"buy pizza"

Question1: Is it that the app has to download/receive that itself. That is the banner that pops up on the phone has to download for itself + my Whatsapp/Telegram has to download again for itself?

My friend replied:

Push notifications can have the message as a payload. Your app could extract that and dynamically insert into the conversation without making an additional request - I've done that before. Makes it feel much snappier. The downside is that you're not guaranteed that pushes will arrive in the correct order (or at all).

But I wasn't convinced, from a semantic point of view, push notifications shouldn't really update your app themselves. It would be an abuse if they do...They should only notify your app of an update and then allow you to do the update yourself through you downloading whatever new content that has been made available.

So to see if the top companies and their apps are applying what my friend suggested I did a little experiment with 3 apps (Gmail, WhatsApp, Telegram):

I turned off Wifi, but kept cellular data on, then I also disabled the app's access from using Cellular data.

enter image description here

Then I had someone send me a message/email: Here are my results:

Telegram:: I get an alert (that has the sender + first line). But once I open the app (or tap on the notification), it doesn’t have my new message or anything.

However, if Telegram is allowed to have access to internet…it downloads the messages in the background…that is if I follow this sequence: I’m wifi or on cellular data with no internet restriction --> receive a notification --> turn internet completely off but then go to app: I will see the complete message/body there.

Gmail: I get an alert (that has a preview of subject/sender/body) But once I open the app, it doesn’t have my new message or anything.

If the Gmail app is allowed to have access to internet…then contrary to Telegram: without only until opening the app itself it will download/update emails in Gmail. I’m guessing Gmail doesn’t have content-available set to 1 but Telegram has it set to 1

WhatsApp: I don’t get anything.

NO interaction happens upon receiving the notification…It only happens if app is downloading itself.

My conclusion is:

NO interaction happens upon receiving the notification…It only happens if app is downloading itself independent from the payload arrival.

Gmail and Telegram are doing a redundant download and basically are't smart enough to what my friend suggested OR that the risk of not receiving an email/message is too much and it’s better to be on the safe side :thinking_face:

Question2: Is that conclusion correct?

Escaut answered 8/6, 2017 at 17:32 Comment(1)
I'm not really pleased with the accepted answer :(. Offered bounty anyways. As for an alternate answer see here. Make sure to read through the commentsEscaut
K
4

First, downloading the payload usually isn't a problem. I'd imagine that the payload is usually very small (probably <1Kb for short text messages). In fact, the maximum size for a regular remote payload is 4KB (5KB for VoIP notifications). See Creating the Remote Notification Payload.

Second, it is hard to have your app access any remote notification data. The only way that is possible is through a Silent Notification, which is not recommended for simple text notifications. A Silent Notification wakes up your app and gives it 30 seconds to perform actions in the background before it is shut down again. You could potentially send a remote Silent Notification that causes your app to manually trigger a regular, local notification based on that remote one (or send both a silent and regular remote notification), but again, such use of Silent Notifications is not recommended:

Silent notifications are not meant as a way to keep your app awake in the background, nor are they meant for high priority updates. APNs treats silent notifications as low priority and may throttle their delivery altogether if the total number becomes excessive. The actual limits are dynamic and can change based on conditions, but try not to send more than a few notifications per hour.

See Configuring a Silent Notification for more info.

Another possible way that apps could "download" remote notifications as they are received is described in Modifying the Payload of a Remote Notification. You could simply save the notifications and choose not to modify them.

There is no universal yes/no answer that works for all apps to either of your questions. Instead, there are a number of different ways that apps could receive remote notifications and process their data.

EDIT: You should also implement application(_:didReceiveRemoteNotification:fetchCompletionHandler:) and retrieve/save data from the user info of the notification so that the data is available faster in your app. However, that method is not guaranteed to be called. So you could/should implement it, but more importantly, have your app check for new data from your own server so that nothing is missed.

Karynkaryo answered 15/6, 2017 at 20:2 Comment(9)
No universal answer? OK...Let me make this very specific. In terms of battery saving and not redownloading things + reliability what's the correct approach for apps like WhatsApp, Telegram?Escaut
As for your suggestion of modifying, not sure why I have to go down that route. What's the application(_:didReceiveRemoteNotification:fetchCompletionHandler:) used for then? Doesn't that get triggered upon receiving a notification?Escaut
You could implement that method and have it retrieve/save user info from the notification (which I recommend doing), but there is a catch: that method is not guaranteed to be called. See here. That method is only meant to make new messages/notifications available faster in-app. However, your app should also be checking its server for new data.Karynkaryo
What do you mean?Karynkaryo
I saw the link (again, I've read it before) you provided. Which part do you find related?Escaut
"However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again." This means, that as your friend described, that method will not necessarily be called if a remote notification is displayed for your app.Karynkaryo
True, so what's the purpose of that function if it's unreliable due to app-termination? Then what's the use case of application(_:didReceiveRemoteNotification:fetchCompletionHa‌​ndler:)? I'm guessing my server has to have a flag for wheter or not something has been downloaded upon receiving the push notification or not. If it was downloaded then all good. If it wasn't then download itEscaut
As I mentioned, That method is only meant to make new messages/notifications available faster in-app. In other words, the OS tells the app about the notification and its content so that it is already there if the user taps the notification to open the app. However, that method is not guaranteed to be called, or in the right order (so include timestamps in your user info). On opening and resuming, your app could query the server for any new messages (or more content such as images for ones it already received), providing the IDs of those that it already received from notifications.Karynkaryo
I see. I'm guessing that also due to size limitations it can't always contain all the message/data...and it can only convey that something new has happened or only offer a preview in which you should do a complete download later onEscaut

© 2022 - 2024 — McMap. All rights reserved.