I am writing an app and using CloudKit. The app stores its data in the public database. I’ve created a local cache so that my app can function even if the network isn’t available. I’m using
CKSubscriptions
and the resulting push notifications to keep changes from the cloud in sync. All of this is working well.Now, if a user has multiple devices and is running my app on all those devices, then it seems that I can no longer mark notifications as “read” (using
CKMarkNotificationsReadOperation
) since I won’t know when all the devices have processed them. This is particularly true if one of the devices is offline when a change happens. If I do mark the notifications as read, then when the other devices check for new notifications (using CKFetchNotificationChangesOperation
) they will not see them and their local cache will be out of date.My current solution is to just leave all notifications in an “unread” state and rely on the
CKServerChangeToken
in CKFetchNotificationChangesOperation
so that each device only grabs the notifications that have occurred since that device last checked. This works OK.But, it seems to me that since I’m not marking any notifications as “read” they will simply continue to pile up on the server. Maybe this isn’t a big deal, but they will take up space and I have no good way to get rid of them. Over time, this seems as if it could be a problem.
As an example, I just did a test with 3 devices. 1st device was on WiFi and the other 2 were in airplane mode. They were all signed in to same iCloud account. I made 3 changes using iCloud Dashboard. The 1st device got the notifications properly and updated its data. It then marked the notifications as read. I turned off airplane mode on the 2nd device. It got notified that the prior notifications had been read:
notificationType
of ReadNotification
, but did not receive the change notifications. 3rd device was the same. It seems to me that each device should get the notifications and should be able to mark them as read individually.Has anyone used subscriptions/notifications in a similar way and come up with a different approach? Also, any feedback on my approach would be welcomed.
Thanks.