本文介绍了我应该在收到有效载荷后更新我的应用吗或者我应该通过允许它自己下载来更新它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当您的iPhone收到WhatsApp / Telegram推送通知时,例如When your iPhone receives a WhatsApp/Telegram push notification e.g.wife:"buy pizza" 问题1:该应用是否必须下载/接收该本身。那个手机弹出的横幅必须自己下载+我的Whatsapp / Telegram必须自己再次下载?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?我的朋友回复:但我不相信,从语义的角度来看,推送通知本身不应该更新你的应用程序。如果他们这样做,那将是一种滥用......他们应该通知您的应用更新,然后允许您通过下载任何已提供的新内容自行进行更新。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.因此,要查看顶级公司及其应用是否正在应用我的朋友建议我使用3个应用(Gmail,WhatsApp,Telegram)进行了一些实验: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):然后我有人给我发了一条消息/电子邮件:这是我的结果: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.但是,如果允许Telegram访问互联网......它会在后台下载消息......即如果我按照序列:我是无线网络或没有互联网限制的手机数据 - >收到通知 - >完全关闭互联网,然后转到应用程序:我会在那里看到完整的消息/正文。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:我收到提醒(主题/发件人/正文预览)但是一旦我打开应用程序,它就没有我的新消息或任何内容。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.如果允许Gmail应用访问互联网...那么与Telegram相反:只有在打开应用程序本身之前,它才会下载/更新Gmail中的电子邮件。我猜Gmail没有内容可用设置为 1 但Telegram将其设置为 1If 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:我什么都没得到。收到通知后没有互动...只有当应用程序正在下载本身NO interaction happens upon receiving the notification…It only happens if app is downloading itself. 我的结论是:收到通知后没有发生任何互动......只有当应用程序正在下载本身时才会发生这种情况。NO interaction happens upon receiving the notification…It only happens if app is downloading itself independent from the payload arrival. Gmail和Telegram正在进行冗余下载,基本上不够智能,我的朋友建议或者没有收到电子邮件/消息的风险太大在安全方面最好:thinking_face: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: 问题2:这个结论是否正确?推荐答案首先,下载有效载荷通常不是问题。我想象有效载荷通常非常小(对于短文本消息,可能 创建远程通知有效负载 。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.其次,很难让您的应用访问任何远程通知数据。唯一可行的方法是通过静默通知,不建议用于简单的文本通知。静音通知会唤醒您的应用,并在再次关闭之前为其提供30秒的时间在后台执行操作。您可能会发送远程静默通知,导致您的应用程序根据该远程通知手动触发常规本地通知(或同时发送静默和常规远程通知),但同样不推荐使用静默通知: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. 编辑:您还应该实施 application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 并从通知的用户信息中检索/保存数据,以便在您的应用中更快地获得数据。但是,不保证调用该方法。所以你可以/应该实现它,但更重要的是,让你的应用程序检查你自己的服务器上的新数据,这样就不会遗漏任何内容。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