How to ensure that iOS app received EVERY push not

2019-04-10 03:47发布

问题:

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. Once device is connected to internet, APNs sends the last notification.

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.

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. Because only one user can be logged in on multiply devices at time.

回答1:

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.