Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

ios - Should I update my app upon receiving payload? Or I should always update it by allowing it to download for itself?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...