CloudKitStorage

class CloudKitStorage(checkpointPath: String, cacheDirectory: String, containerIdentifier: String? = null, zoneName: String = "backupkit", recordType: String = "BackupEntry", environment: String = "") : CloudStorage(source)

CloudKit transport: one custom zone in the user's private database, one record per file, the bytes as a CKAsset. Unlike the iCloud Drive container there are no placeholder files: a save completes when Apple's server has the record, and a read is a network fetch with a definite outcome.

  • remoteId is always null and sizes are always known.

  • list fetches zone changes since the last checkpoint (checkpointPath, one atomic JSON file holding the change token together with the records it stands for) and never downloads assets.

  • readBytes and downloadFile serve from a local cache under cacheDirectory when the cached copy matches the record's change tag; prefetch fills that cache eight records per request, two requests in flight.

  • Pass environment as "development" for debug builds and "production" otherwise: Xcode's debug builds talk to the Development container, and the two must never share a checkpoint on one device.

Entitlements: com.apple.developer.icloud-services = [CloudKit] and the container in com.apple.developer.icloud-container-identifiers. The BackupEntry record type and the zone are created automatically in the Development environment; deploy the schema to Production in the CloudKit console before a TestFlight build.

Constructors

Link copied to clipboard
constructor(checkpointPath: String, cacheDirectory: String, containerIdentifier: String? = null, zoneName: String = "backupkit", recordType: String = "BackupEntry", environment: String = "")

Properties

Link copied to clipboard
open override val provider: CloudProvider

Functions

Link copied to clipboard
open suspend override fun availability(): CloudAvailability

Cheap. Never touches the network.

Link copied to clipboard
open suspend override fun delete(path: String, remoteId: String?)

No-op when already absent.

Link copied to clipboard
open suspend override fun downloadFile(path: String, toLocalPath: String, remoteId: String?)

Downloads into toLocalPath, replacing it. Throws CloudError.NotFound when absent.

Link copied to clipboard
open suspend override fun exists(path: String): Boolean
Link copied to clipboard
open suspend override fun identityKey(): String?

Stable per (device, cloud account) when the platform can tell, so a sync engine can detect an account switch. Null on Drive, where the engine keys identity off the marker file's id.

Link copied to clipboard
open suspend override fun list(): List<RemoteFile>

Every file, deduplicated by path (newest wins).

Link copied to clipboard
open suspend override fun prefetch(paths: List<String>)

Starts downloading every not-yet-local file in paths at once, without waiting. iCloud only; Drive has nothing to prefetch. Never throws. Call it before a restore so files download in parallel instead of one at a time.

Link copied to clipboard
open suspend override fun readBytes(path: String, remoteId: String?): ByteArray?

Whole contents, or null when absent. Forces an iCloud download first.

Link copied to clipboard
open suspend override fun writeBytes(path: String, bytes: ByteArray, mimeType: String, existingRemoteId: String?): String?

Create or replace from memory. Returns the remote id on Drive, null on iCloud.

Link copied to clipboard
open suspend override fun writeFile(path: String, localPath: String, mimeType: String, existingRemoteId: String?): String?

Create or replace from a local file. Returns the remote id on Drive, null on iCloud.