ios – iCloud Sync Not Working on Device, but is Working in Simulator


I have iCloud sync working in the simulator, where I signed in with my Apple ID on two simulators and it syncs fine. But when I upload the same build to TestFlight and install it on two of my physical devices, it does not sync. Each device behaves as if they only have a local store, eg. each can save and load fine locally. I already tried pushing my schema to production, but it still does not work, even when given 24 hours to see if it would sync. I have also tried restarting both devices and deleting and re-installing the app on both devices. I have also confirmed that iCloud is turned on in the settings app for my app.

I saw this post on Stackoverflow, which seems to be related to my issue, but the suggestions there did not work either. I also saw this post, but I did not understand the accepted answer, and none of the other suggestions worked either.

I’m just asking what has to change from a simulator to a physical device. The implementation is just the sample project in Xcode with core data and CloudKit checked.

Here is my code:

struct PersistenceController {

    static let shared = PersistenceController()
    let container: NSPersistentCloudKitContainer
    
    init(inMemory: Bool = false) {
        container = NSPersistentCloudKitContainer(name: "Model")
        if inMemory {
            container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
        }
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        container.viewContext.automaticallyMergesChangesFromParent = true
    }

}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img