如何确保 iOS 应用收到服务器发送的每个推送通知? [英] How to ensure that iOS app received EVERY push notification send by server?

查看:23
本文介绍了如何确保 iOS 应用收到服务器发送的每个推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知:

  • 应用在后台或离线模式下不会收到推送通知(应用在用户操作后收到一次:点击通知或应用图标).
  • Apple 推送通知服务在设备离线时保持最后一条通知.设备连接到互联网后,APN 会发送最后一条通知.
  • app doesn't receive push notification if it is in background or offline mode (app gets it once after user's action: tap on notification or app icon).
  • Apple push Notification service keep only ONE last notification when device is offline. Once device is connected to internet, APNs sends the last notification.

如何解决这个问题?

  • 刚刚到达应用(非设备)的最新通知必须反映尚未在应用中实现的实际通知数量.因此,我可以随时从服务器下载最后的 n 条通知并在应用中实现它们.
  • very latest notification that just reached the app (not device) must reflect the actual number of notifications that are not implemented in the app yet. So, then I can download from the server last n notifications and implement them in the app at any time.

问题是:

服务器如何知道应用中实现了哪些通知,哪些没有?

通知必须针对每个设备.为什么?例如,通知从核心数据中删除对象"必须在每个设备中实现.因为只有一个用户可以同时登录多个设备.

Notifications must be per device. Why? For instance, notification "remove object from Core Data" must be implemented in every device. Because only one user can be logged in on multiply devices at time.

推荐答案

您应该在服务器上跟踪任务的状态(删除记录或您的应用程序需要执行的任何操作),并在任务完成时让客户端报告.然后将任务标记为已完成.

You should track the state of the task (delete record or whatever your app needs to do) on the server and have the client report back when the task is done. Then flag the task as done.

不要将推送通知用作任务的可靠传递方式,否则您会失败.将通知用作设置的补充部分.

Don't use push notifications as a reliable delivery method for your tasks, you will fail. Use the notifications as complementary part of your setup.

例如,当您的应用收到通知时,它可以与后端同步,以检索标记为未完成的任务,执行它们,然后让后端知道它已完成.

So for example when your app receives a notification, it can sync with the backend, to retrieve the tasks flagged as not done, execute them and then let the backend know that it's done.

这篇关于如何确保 iOS 应用收到服务器发送的每个推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆