Search code examples
swiftcore-dataicloudcloudkitnspersistentcloudkitcontainer

iCloud Sync does work on iPhone & Mac but not on iPad


I have found a strange problem with iCloud Sync.

Situation: I have developed an iOS, iPadOS & macOS App using SwiftUI. All three Versions share the same Codebase (macOS Version is a Catalyst iPad Version). The Project does support iCloud Sync via the NSPersistenceCloudKitContainer to sync data between all 3 devices.

Problem: iCloud Sync works perfectly between my iPhone and my Mac, but when using it with my iPad, I face a really strange problem. When creating a new CoreData Object on my iPad, it will appear on my other devices after a few Seconds, which is totally fine. However, when creating the CoreData Object on my iPhone or Mac, it will not appear on the iPad (I waited 10min). Only when closing and reopening the App, the Object will appear.

Details: I not even have to fully exit the App. It is enough to just swipe up to Application Picker and select the App again.

Question: Does anyone has an idea or something what could cause this strange error? And remember: All three devices are using the same codebase.


Solution

  • Make sure your have enabled Push and remote notifications per the Apple Documentation

    Project Settings > Signing and Capabilities 
    

    Sync CoreData with CloudKit using

    try? persistentContainer.viewContext.setQueryGenerationFrom(.current)