CloudKit not working properly in iOS 17 RC

CloudKit was working perfectly in iOS 16. However after updating to iOS 17 RC on my devices iCloud sync no longer works properly.

The app has a package called CloudKitSyncMonitor which shows the sync status. Normally it would say Synced with iCloud but on iOS 17 it is either stuck in the Syncing or Sync not started state and the data doesn’t update. This mostly happens after a reinstall of the app. After some time it randomly decides to work until I uninstall the app.

I’m really confused what could be the problem if it was working fine on iOS 16 but barely works properly on iOS 17? This is currently the code I have for the DataController:

import SwiftUI
import CoreData

class DataController {
    var container: NSPersistentCloudKitContainer
    @AppStorage(wrappedValue:true,"syncEnabled",store:UserDefaults(suiteName: "group.com.ip18.SubManager")) var syncEnabled
    static let shared = DataController()
    init() {
        container = NSPersistentCloudKitContainer(name: "Subscriptions")
        load(syncEnabled: syncEnabled)
    }
    
    func load(syncEnabled: Bool = true) {
        container = NSPersistentCloudKitContainer(name: "Subscriptions")
        let url = URL.storeURL(for: "group.com.ip18.SubManager", databaseName: "Subscriptions")
        let storeDescription = NSPersistentStoreDescription(url:url)
        if syncEnabled {
            storeDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.ip18.SubManager")
        } else {
            storeDescription.cloudKitContainerOptions = nil
        }
        let remoteChangeKey = "NSPersistentStoreRemoteChangeNotificationOptionKey"
        storeDescription.setOption(true as NSNumber, forKey: remoteChangeKey)
        storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
        container.persistentStoreDescriptions = [storeDescription]
        container.viewContext.automaticallyMergesChangesFromParent = true
        /*
        // Only initialize the schema when building the app with the
        // Debug build configuration.
        #if DEBUG
        do {
            // Use the container to initialize the development schema.
            try container.initializeCloudKitSchema(options: [])
        } catch {
            // Handle any errors.
        }
        #endif
        */
        container.loadPersistentStores(completionHandler: {(storeDescription,error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error)")
            }
        })
    }
}

I had the same issue yesterday, and spent 4 hours trying everything eventually making it working. I think two things helped: resetting developer environment at iCloud console, and turning on and off CloudKit checkboxes in targets' "Singing & Capabilities". Everything I've done with data controller itself was fruitless, I guess it's something to do with certificates, entitlements, signatures, all that stuff. Not code itself.

I'm running into what sounds like a similar issue. CloudKit CoreData sync worked perfectly in iOS 16/watchOS 9, but is no longer working reliably in iOS 17/watchOS 10. Previously, the watchOS and iOS apps would be in sync within seconds, but now it takes hours. The iOS app seems to work better after a reinstall, but the watchOS app is unreliable. Even a with a delete and reinstall, it finally randomly syncs after minutes or hours and does not stay in reliably in sync afterward.

Looking at the CloudKit live streaming log, iOS 17 seems to be quite active immediately when there is a database update to push, but watchOS 10 is inactive when it should be receiving or pushing an update.

Appreciate any insights or experiences others might have. The same code across both apps has worked reliably since iOS 13/watchOS 6...until now.

Please file a Feedback (https://developer.apple.com/bug-reporting/) and link it here, including a sysdiagnose covering your reproduction with CloudKit logging enabled (https://developer.apple.com/bug-reporting/profiles-and-logs/?name=cloudkit). That will hopefully allow us to understand the root cause of the symptoms you see. Thank you!

Any update on this issue? It’s still present in 17.0.2.

Looking at the app privacy report it never makes any attempt to connect to iCloud servers.

I also noticed this when looking at the logs:

Background Task 5 ("CoreData: CloudKit Setup"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.

CloudKit not working properly in iOS 17 RC
 
 
Q