3

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.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

2

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.

Zoltán
  • 1,422
  • 17
  • 22
  • Thanks for reply. Should I keep on the server info whether task was done or not per device? For instance, If task is "remove item for user A" then should I keep 4 same tasks for every device where user A was logged in? Do I understand it? – Bartłomiej Semańczyk Oct 04 '15 at 12:22
  • 1
    I wouldn't keep track per device on the server, but on each device. You never know when a users adds or removes a device... I would work with a change-log serverside, where each change (add/edit/delete) will get a unique ID. On your device you keep track of the ID you're currently at, and when you sync, you sync from that number until the last one in the change-log. This way you can do this per device. – Glenn Oct 04 '15 at 13:17
  • @Glenn so what is better approach? Keep track on server per device, or keep id of last done notification on the device...? – Bartłomiej Semańczyk Oct 05 '15 at 06:46
  • 1
    Keeping track of the last done notification on a device is (in my opinion) better: it's easier to implement and in terms of encapsulation it's also a better way: the server doesn't need to know how many and/or which devices you have. – Glenn Oct 05 '15 at 07:55