debug: add CloudKit container diagnostics to sync logs

Logs bundle ID, CKContainer.default() identifier, and iCloud account
status at sync start to help diagnose "Invalid bundle ID for container"
errors on TestFlight.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-02-10 19:30:50 -06:00
parent 53cc532ca9
commit c6fa6386fd

View File

@@ -8,6 +8,7 @@
import SwiftUI import SwiftUI
import SwiftData import SwiftData
import BackgroundTasks import BackgroundTasks
import CloudKit
@main @main
struct SportsTimeApp: App { struct SportsTimeApp: App {
@@ -238,6 +239,21 @@ struct BootstrappedContentView: View {
let log = SyncLogger.shared let log = SyncLogger.shared
log.log("🔄 [SYNC] Starting background sync...") log.log("🔄 [SYNC] Starting background sync...")
// Log diagnostic info for debugging CloudKit container issues
let bundleId = Bundle.main.bundleIdentifier ?? "unknown"
let container = CKContainer.default()
let containerId = container.containerIdentifier ?? "unknown"
log.log("🔧 [DIAG] Bundle ID: \(bundleId)")
log.log("🔧 [DIAG] CKContainer.default(): \(containerId)")
if let entitlementContainers = Bundle.main.object(forInfoDictionaryKey: "com.apple.developer.icloud-container-identifiers") as? [String] {
log.log("🔧 [DIAG] Entitlement containers: \(entitlementContainers.joined(separator: ", "))")
}
if let accountStatus = try? await container.accountStatus() {
log.log("🔧 [DIAG] iCloud account status: \(accountStatus.rawValue) (0=couldNotDetermine, 1=available, 2=restricted, 3=noAccount)")
} else {
log.log("🔧 [DIAG] iCloud account status: failed to check")
}
// Only reset stale syncInProgress flags; do not clobber an actively running sync. // Only reset stale syncInProgress flags; do not clobber an actively running sync.
let syncState = SyncState.current(in: context) let syncState = SyncState.current(in: context)
if syncState.syncInProgress { if syncState.syncInProgress {