Menu

Detecting and recovering from a deleted CloudKit zone with CKSyncEngine
📰

Detecting and recovering from a deleted CloudKit zone with CKSyncEngine

DEV Community: ios·Darkø Tasevski·about 18 hours ago
#Q3Eg2tX3
#devtoios#devto#dev#zone#engine
Long article (1903 words) — no AI summary yet.
Reading 0:00
15s threshold

For the past while I've been testing CKSyncEngine for a reading app of mine, with two iPads on the same iCloud account and a library of about 14,000 books, and most of it behaved the way Apple's docs and the WWDC session describe. The part that didn't is what happens when the record zone your data lives in gets deleted, so these are my notes on how that deletion reaches the app, and on what went wrong when we tried to recover from it.

How a deleted zone reaches you

There are two ways the engine tells you the zone is gone. On the read path it comes as a database change, with a reason attached, and the reason decides what we do next. Only .deleted means "recreate the zone and upload again", since .purged (the user deleted the app's iCloud data) and .encryptedDataReset (the user reset their encryption keys) mean the user wants that data gone, so for those we stop syncing instead:

func handleEvent ( _ event : CKSyncEngine . Event , syncEngine : CKSyncEngine ) async { switch event { case .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.