iCloud Sync Diagnostics
Overview
Core principle 90% of cloud sync problems stem from account/entitlement issues, network connectivity, or misunderstanding sync timingβnot iCloud infrastructure bugs.
iCloud (both CloudKit and iCloud Drive) handles billions of sync operations daily across all Apple devices. If your data isn't syncing, the issue is almost always configuration, connectivity, or timing expectations.
Red Flags β Suspect Cloud Sync Issue
If you see ANY of these:
- Files/data not appearing on other devices
- "iCloud account not available" errors
- Persistent sync conflicts
- CloudKit quota exceeded
- Upload/download stuck at 0%
- Works on simulator but not device
- Works on WiFi but not cellular
β FORBIDDEN "iCloud is broken, we should build our own sync"
- iCloud infrastructure handles trillions of operations
- Building reliable sync is incredibly complex
- 99% of issues are configuration or connectivity
Mandatory First Steps
ALWAYS check these FIRST (before changing code):
func checkICloudStatus() async {
let status = FileManager.default.ubiquityIdentityToken
if status == nil {
print("β Not signed into iCloud")
print("Settings β [Name] β iCloud β Sign in")
return
}
print("β
Signed into iCloud")
let container = CKContainer.default()
do {
let status = try await container.accountStatus()
switch status {
case .available:
print("β
CloudKit available")
case .noAccount:
print("β No iCloud account")
case .restricted:
print("β iCloud restricted (parental controls?)")
case .couldNotDetermine:
print("β οΈ Could not determine status")
case .temporarilyUnavailable:
print("β οΈ Temporarily unavailable (retry)")
@unknown default:
print("β οΈ Unknown status")
}
} catch {
print("Error checking CloudKit: \(error)")
}
}
func checkEntitlements() {
if let containerURL = FileManager.default.url(
forUbiquityContainerIdentifier: nil
) {
print("β
iCloud container: \(containerURL)")
} else {
print("β No iCloud container")
print("Check Xcode β Signing & Capabilities β iCloud")
}
}
func checkConnectivity() {
print("Network: Check if device has internet")
print("Try on different networks (WiFi, cellular)")
}
func checkStorage() {
let homeURL = FileManager.default.homeDirectoryForCurrentUser
if let values = try? homeURL.resourceValues(forKeys: [
.volumeAvailableCapacityKey
]) {
let available = values.volumeAvailableCapacity ?? 0
print("Available space: \(available / 1_000_000) MB")
if available < 100_000_000 {
print("β οΈ Low storage may prevent sync")
}
}
}
Decision Tree
CloudKit Sync Issues
CloudKit data not syncing?
ββ Account unavailable?
β ββ Check: await container.accountStatus()
β ββ .noAccount β User not signed into iCloud
β ββ .restricted β Parental controls or corporate restrictions
β ββ .temporarilyUnavailable β Network issue or iCloud outage
β
ββ CKError.quotaExceeded?
β ββ User exceeded iCloud storage quota
β β Prompt user to purchase more storage
β β Or delete old data
β
ββ CKError.networkUnavailable?
β ββ No internet connection
β β Check WiFi/cellular
β β Test on different network
β
ββ CKError.serverRecordChanged (conflict)?
β ββ Concurrent modifications
β β Implement conflict resolution
β β Use savePolicy correctly
β
ββ SwiftData not syncing?
ββ Check ModelConfiguration CloudKit setup
ββ Verify private database only (no public/shared)
ββ Check for @Attribute(.unique) (not supported with CloudKit)
iCloud Drive Sync Issues
iCloud Drive files not syncing?
ββ File not uploading?
β ββ Check: url.resourceValues(.ubiquitousItemIsUploadingKey)
β ββ Check: url.resourceValues(.ubiquitousItemUploadingErrorKey)
β ββ Error details will indicate issue
β
ββ File not downloading?
β ββ Not requested? β startDownloadingUbiquitousItem(at:)
β ββ Check: url.resourceValues(.ubiquitousItemDownloadingErrorKey)
β ββ May need manual download trigger
β
ββ File has conflicts?
β ββ Check: url.resourceValues(.ubiquitousItemHasUnresolvedConflictsKey)
β ββ Resolve with NSFileVersion
β
ββ Files not appearing on other device?
ββ Check iCloud account on both devices (same account?)
ββ Check entitlements match on both
ββ Wait (sync not instant, can take minutes)
ββ Check Settings β iCloud β iCloud Drive β [App] is enabled
Common CloudKit Errors
CKError.accountTemporarilyUnavailable
Cause: iCloud servers temporarily unavailable or user signed out
Fix:
if error.code == .accountTemporarilyUnavailable {
try await Task.sleep(for: .seconds(5))
try await retryOperation()
}
CKError.quotaExceeded
Cause: User's iCloud storage full
Fix:
if error.code == .quotaExceeded {
showAlert(
title: "iCloud Storage Full",
message: "Please free up space in Settings β [Name] β iCloud β Manage Storage"
)
}
CKError.serverRecordChanged
Cause: Record modified on server since your last fetch. Most common root cause: saving a stale record without fetching the latest version first.
Diagnosis β check the simple fix FIRST:
let record = CKRecord(recordType: "Note", recordID: existingID)
record["title"] = "Updated"
try await database.save(record)
let record = try await database.record(for: existingID)
record["title"] = "Updated"
try await database.save(record)