简体   繁体   English

如何确保iOS应用程序收到服务器发送的每个推送通知?

[英]How to ensure that iOS app received EVERY push notification send by server?

It is widely known that: 众所周知:

  • 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. 当设备离线时,Apple推送通知服务保留最后一个通知 Once device is connected to internet, APNs sends the last notification. 设备连接到Internet后,APN会发送最后一个通知。

How to solve this? 怎么解决这个?

  • 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. 那么,我可以从服务器上下载最后n通知,并随时在应用程序中实现它们。

The question is: 问题是:

How the server knows what notifications were implemented in the app, and which one not? 服务器如何知道在应用程序中实现了哪些通知,哪一个没有?

Notifications must be per device. 通知必须是每台设备。 Why? 为什么? For instance, notification "remove object from Core Data" must be implemented in every device. 例如,必须在每个设备中实现通知“从Core Data中删除对象”。 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. 因此,例如,当您的应用收到通知时,它可以与后端同步,检索标记为未完成的任务,执行它们,然后让后端知道它已完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM