10

I am New to cloud Kit can someone Help me with Error , as i am trying to implement add a record in my Public Database and Getting this Error .

"Bad Container" (5/1014); "Couldn't get container configuration from the server for container "iCloud.com.abc.def""

THANKS .

Alex A
  • 107
  • 1
  • 4

5 Answers5

9

Is that the bundle ID of your application? Xcode creates a container on the server with the bundle ID of the current application. Double-check your application's bundle ID then follow the instructions in the CloudKit Quick Start to set up that container.

farktronix
  • 3,880
  • 1
  • 21
  • 27
  • 3
    The CKContainer ID isn't equal to the app bundle ID as it has "iCloud." prefix. Also, it is allowed for an app to access multiple containers as it is specified in http://stackoverflow.com/questions/33478860/can-you-share-data-on-cloudkit-between-different-apps, so it isn't required for a container ID to bear any resemblance to bundle ID at all – Max Desiatov Jan 03 '16 at 19:02
9

Please make sure that you've initialised the container properly. You can double-check with iCloud Dashboard if it has your container in the containers list.

The container is initialised with CKContainer.defaultContainer() call or a more specific CKContainer(identifier: String) initialiser. Bear in mind that CloudKit container ID is usually in the form iCloud.<bundleID>, where <bundleID> is the bundle ID of your app. So the root of the problem might be that you tried to share a container between different apps but forgot to add iCloud. prefix.

Max Desiatov
  • 5,087
  • 3
  • 48
  • 56
  • 1
    Thanks. This also happens if you enter a specific string for the container under Signing & Capabilities. In that case you are not using the defaultContainer and must specify a container with that string as identifier. – Peter B. Kramer Mar 20 '22 at 04:42
  • I was missing the `iCloud.` prefix. Thanks – mttcrsp Feb 01 '23 at 22:17
1

I solved problem renaming bundle of my new app to the same name as was container name in CloudKit.

It shouldn't work like that because by design many apps can have access to the same container, but apparently there is no way in CloudKit dashboard or on developer account to "add new bundle ID to container".

Sebastian
  • 448
  • 4
  • 14
  • This is certainly 'bringing the mountain to Mohamed'. It would have been easier to change defaultContainer to containerWithIdentifier:@"MySpecificContainerName" – Peter B. Kramer Mar 20 '22 at 04:46
1

This error can also occur when you add a CKOperation to a custom OperationQueue without defining the database property of the operation.

Ely
  • 8,259
  • 1
  • 54
  • 67
0

Try to debug this issue by catching the error when you use one of the database's operations (e.g.: catch, fetch).

Example:

let publicDatabase = CKContainer.default().publicCloudDatabase
                    publicDatabase.save(record) { (rec, err) in
                       
                        if let error = err {
                            
                            print("Error while saving record: \(error)")
                            
                        }

or use the debugger instead.

You could possibly have a mismatch between the Apple CloudKit container's identifier and the CKContainer.default() container identifier. You can correct this by choosing the container identifier

let myPublicDatabase = CKContainer.init(identifier: "iCloud.com.abc.def").publicCloudDatabase