本文介绍了我应该在收到有效负载后更新我的应用程序吗?或者我应该总是通过允许它自己下载来更新它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您的 iPhone 收到 WhatsApp/Telegram 推送通知时,例如

妻子:买披萨"

问题 1:应用是否必须下载/接收本身.那就是手机上弹出的横幅必须自己下载 + 我的 Whatsapp/Telegram 必须自己重新下载?

我朋友回复:

推送通知可以将消息作为有效负载.你的应用可以提取它并动态插入到对话中,而无需提出一个额外的要求——我以前做过.让人觉得快得多.缺点是你不能保证推送将按正确的顺序(或根本没有)到达.

但我不相信,从语义的角度来看,推送通知不应该真正更新您的应用程序本身.如果他们这样做,那将是一种滥用行为...他们应该只通知您的应用有更新,然后允许您通过下载任何可用的新内容自行进行更新.>

所以为了看看顶级公司及其应用程序是否正在应用我朋友的建议,我对 3 个应用程序(Gmail、WhatsApp、Telegram)做了一个小实验:

我关闭了 Wifi,但保持蜂窝数据开启,然后我还禁止使用蜂窝数据访问该应用.

然后有人给我发了一条消息/电子邮件:这是我的结果:

电报::我收到一条警报(有发件人 + 第一行).但是一旦我打开应用程序(或点击通知),它就没有我的新消息或任何东西.

但是,如果 Telegram 被允许访问互联网......它会在后台下载消息......也就是说,如果我按照这个顺序:我是 wifi 或蜂窝数据,没有互联网限制--> 收到通知 --> 完全关闭互联网,然后转到应用程序:我会在那里看到完整的消息/正文.

Gmail:我收到一条提醒(有主题/发件人/正文的预览)但是一旦我打开应用程序,它就没有我的新邮件或任何内容.

如果 Gmail 应用程序被允许访问互联网……那么与 Telegram 相反:除非打开应用程序本身,它才会下载/更新 Gmail 中的电子邮件.我猜 Gmail 没有将 content-available 设置为 1 但 Telegram 将它设置为 1

WhatsApp:我什么也没收到.

收到通知后不会发生任何交互……只有当应用正在下载本身时才会发生这种情况.

我的结论是:

收到通知后不会发生任何交互……只有当应用下载自身时,与有效载荷到达无关.

Gmail 和 Telegram 正在执行冗余下载,基本上不够聪明,无法满足我朋友的建议,或者未收到电子邮件/消息的风险太大,最好安全一点:thinking_face:

问题 2:这个结论正确吗?

解决方案

首先,下载有效负载通常不是问题.我认为有效载荷通常非常小(对于短文本消息,可能小于 1Kb).事实上,常规远程有效负载的最大大小为 4KB(VoIP 通知为 5KB).请参阅创建远程通知负载.

其次,您的应用很难访问任何远程通知数据.唯一可能的方法是通过静默通知,不建议将其用于简单的文本通知.静默通知会唤醒您的应用,并在再次关闭之前为其提供 30 秒的时间在后台执行操作.您可能会发送一个远程静默通知,导致您的应用程序手动触发基于该远程通知的常规本地通知(或同时发送静默和常规远程通知),但同样,不建议使用静默通知:

静默通知并不意味着让您的应用在后台保持唤醒状态,也不意味着它们用于高优先级更新.APNs 将静默通知视为低优先级,如果总数过多,可能会完全限制它们的传递.实际限制是动态的,可以根据条件变化,但尽量不要每小时发送超过几个通知.

参见 配置静默通知了解更多信息.

应用程序可以在收到远程通知时下载"它们的另一种可能方式在 修改远程通知的有效负载.您可以简单地保存通知并选择不修改它们.

对于您的任何一个问题,都没有适用于所有应用程序的通用是/否答案.相反,应用可以通过多种不同的方式接收远程通知并处理其数据.

编辑:您还应该实现application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 并从通知的用户信息中检索/保存数据,以便数据在您的应用中更快地可用.但是,不能保证调用该方法.因此,您可以/应该实施它,但更重要的是,让您的应用检查来自您自己的服务器的新数据,以免遗漏任何数据.

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:

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.

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?

解决方案

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:

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.

这篇关于我应该在收到有效负载后更新我的应用程序吗?或者我应该总是通过允许它自己下载来更新它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:23