Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing CKQuerySubscriptions

I'd like to introduce the usage of CloudKit in an app I am developing. As a first step I'd use it for handling push notifications when certain records are inserted in the public database. So in my app I would create a CKQuerySubscription for each record type I'd like to monitor.

My question is: what's the best strategy to renew these subscriptions? While testing I noticed my development container messed up a few times and I had to reset it to get subscriptions to behave as they should. Apple does not state anything in the documentation, so when is one supposed to delete an existing subscription and recreate it? Since over time the notification info for a subscription might change, I thought of recreating all subscriptions each time the build number is different. Is this a good approach to avoid messing up the production version of the container?

like image 934
user3075898 Avatar asked Apr 21 '26 01:04

user3075898


1 Answers

In my scenario, I added a check at startup to fetch all the subscriptions and validate that the expected subs are there. This way I can reset, change containers or even deal with vanishing subs (i have not seen subs vanish, but if it should happen, I can recover gracefully).

This would also give you a place to update subs, if your notifications need to change. Fetch them all then purge/replace as needed.

With that approach you don’t need to continually rebuild your subs. You’ll refresh just when they’re missing or you update your check logic to look for different subs.

like image 67
Thunk Avatar answered Apr 23 '26 14:04

Thunk