0
votes

As the title suggests I'm in the process of releasing an app which is using Core Data and CloudKit to sync user data across multiple devices. In order to distribute the app through TestFlight and later through the App-Store I have to deploy my CloudKit Container to production mode. Unfortunately, that seems not possible for me at the moment.
So by following this guide https://developer.apple.com/documentation/cloudkit/managing_icloud_containers_with_the_cloudkit_database_app/deploying_an_icloud_container_s_schema I selected the "Deploy Schema Changes" button on the left side and confirmed the deployment.

enter image description here

enter image description here
After that I even get a success message but at the top below the actual Container-Selection it still says "This container has not been deployed to Production".
Success Message

enter image description here

So what am I missing?

1

1 Answers

1
votes

Before deploying the schema you need to initialize it. Based on your screenshots, it looks like you didn't do it, since zero changes were applied (screenshot 2). You could also see what Record Types you have in Schema section - my guess is that no it is empty.

You could initialize a scheme with a following code:

    let options = NSPersistentCloudKitContainerSchemaInitializationOptions()
    try? container.initializeCloudKitSchema(options: options)
            

You need to put in AppDelegate in pesistentContainer, so it looks like this:

lazy var persistentContainer: NSPersistentCloudKitContainer = {
    let container = NSPersistentCloudKitContainer(name: "")
    
    container.loadPersistentStores(completionHandler: { })
    
    let options = NSPersistentCloudKitContainerSchemaInitializationOptions()
    try? container.initializeCloudKitSchema(options: options)
            
    return container
}()

After that you will see a number of Record Types changed in the "Confirm Deployment" window.

You should also comment out two lines related to options since there is no need to initialize the scheme every time. When you need to update the scheme again, just comment in these lines.

Also keep in mind that record types cannot be changed once deployed.