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)")
}
})
}
}