Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a sync of IOS reminders programmatically be triggered / forced?

I am writing a task mgmt app that is using EKReminder. Works perfectly when using on one iOS device.

When I use on two devices (same apple account), I realise that reminder changes sync is with significant delay and even often incomplete. (tried iCloud, google, company outlook)

This thus seems unrelated to my app (same happens if I change reminders directly in Reminder iOS app).

Can I programmatically force a sync of reminders with whatever service (e.g. iCloud) that they are linked to and trigger this out of my app?

like image 896
TPeter Avatar asked Apr 07 '17 12:04

TPeter


1 Answers

@Losiowaty suggests a valid solution in the comments to the question, but I think there's a bit more information the following solution(s) could provide. To be fair, I have actually noticed this exact same issue specifically with the Apple Reminders app, and think that in general the solution applies to iOS but could carry over to the same notifications that have similar issues on macOS as well.

For iOS, though, the issue seems to be:

  • Two iOS devices on the same Apple iCloud account will both get a specific Reminder push notification. The issue is, though, that clearing that push notification on 1 device does not sync the second device properly in almost all cases as of right now. This is the question asked above's context, from what I understand.

The second, not as well recognized problem, from what I can tell, is that this problem is due to the fact the "host" application isn't properly clearing it's own push notifications, so to speak. What I mean by this is:

  • iPad and iPhone receive push notification from Reminders app about a 12:00 TODO item, at 12:00.
  • iPad push notification is acted on, marked as completed, and cleared on iPad immediately
  • iPhone push notification is still there (the issue we're attempting to solve), but will likely not be removed until itself is removed (opening Reminders app not from the push notification will often not clear this).

The reason for this is the push notification isn't being cleared by the application, and so even though it's now irrelevant information (since it was cleared after being marked as completed (or snoozed) on another device), but the push notification system doesn't know that (since pushes are just payloads of information, unless you properly use TTL on these, but that's a different answer). The way to fix that, that most/some apps use to an extent, could be:

1) As stated in the comment, in bullet point 2 the action (marked as completed, and cleared from device 1) could update the backend (iCloud in this case) that this item is complete, which then sends a silent push to all associated devices which properly clears the push notification (this would likely happen in a form of an application background task, something like a Notification Service Extension Apple link here (iOS 10+ only)

2) Another method would be to keep an internal "secret" key unique to each push notification you send (across all associated devices). You can then associate any one "task" object (in the Reminders app context as an example, but this can really be any data object held in your app) with a set of push notification "secret" keys (which can expire on a custom timer if you feel these are getting out of hand, especially since pushes will likely be viewed OR irrelevant after 30 days in most use cases). From this, along with a mechanism to make the application update it's data, if the app notices the device has any push notifications it shouldn't (based on the set of "secret" keys which are associated with "active" data), it should clear them for you. This ends up with the same result as method 1, but doesn't require a silent push (a socket can be used, or something else entirely), and could rely on a basic background job

It looks like either way, you need some kind of background task processing to act when something happens (either through a notification service extension as linked or through a simple background task that Apple supports).

I hope this answers your question and points you in the right direction for what you are building!

like image 108
BHendricks Avatar answered Oct 22 '22 16:10

BHendricks