Invalid Bundle ID for container

Created a branch new app from scratch with the appropriate CloudKit capability and a brand new container. Any attempt to fetch or save a record to the private database results in the error message "Invalid bundle ID for container". I am using the default container.

Previous posts about this issue have suggested "disassosciating" and "reassosciating" my apps container by toggling it's cloud kit capability in it's identifier settings via the developer portal. This does not work.

Previous posts have also suggested that this could be a permissions issue, so I went into the database schema and gave as many permissions as I could for each of the default roles. This also does not work.

This is only a problem for the app. The database is fully editable from the dashboard.

I tried creating new apps and new containers from scratch, each with different bundle and container IDs and they all exhibit this behavior.

I've created half a dozen or so working CloudKit applications before and this is the first time I've seen this. Can anyone from apple let me know:
  1. what exactly does this error indicate? in what way is my apps bundle ID invalid?

  2. I am assuming that the error message here is not actually indicating what the real problem is. What is the real problem?

I can't even begin to express my frustration with these API's. They break so frequently, are poorly documented, the error messages are misleading, and half the time they seem to magically "fix themeselves" after an XCode or OSX update with no explanation.


Yep, having this issue, very annoying - I hope it'll be fixed in the next few days as it seems to be an issue on Apple's side.

Meanwhile I've filed a radar: FB8877360, and also posted here: https://developer.apple.com/forums/thread/665280

Currently experiencing this as well, and it’s causing a huge roadblock in my development.
I found a solution for my case, so I'm posting to help anyone else with a similar setup.

If you're sharing a CloudKit container across multiple apps (using different bundle IDs), apart from specifying the container identifier when initializing the container, you must set NSPersistentCloudKitcontainerOptions on the NSPersistentCloudKit container (this is in the AppDelegate if you selected the "Use CloudKit" option during project creation) as shown below:

Code Block
let container = NSPersistentCloudKitContainer(name: "ModelName")
guard let description = container.persistentStoreDescriptions.first else {
fatalError("No container descriptions available")
}
description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier:"iCloud.com.organization.ContainerName")
container.persistentStoreDescriptions = [ description ]


In your code, when you access the desired container, you use the same container ID as in the description above:
Code Block
let container = CKContainer(identifier: "iCloud.com.organization.ContainerName")


You can use this method to specify and access multiple containers as well.

I found my solution in the WWDC 19 talk: https://developer.apple.com/videos/play/wwdc2019/202/
Same here... also lybron's answer did not help in my case

I had the same issue, I had retrieved the container via: let container = CKContainer.default() spent a few hours one day working on it, then the following morning decided to try: let container = CKContainer(identifier: "mycontainer.id") and it worked.

So I tried print the default container identifier, which turned out to be mycontainer.id -- so I reverted my code to: let container = CKContainer.default() and it worked again.

My conclusion is that either:

  • calling it with the identifier explicitly fixed some setting, to make it match the setting in the XCode project settings (which had always been mycontainer.id),

or:

  • there was an issue where Apple had to finish updating some database permissions or something internally, which took a few hours or more (less than a day in my case though thankfully).

Anyway, figured I'd post this in case for when someone else runs into it -- seems to be a reasonably common issue.

I had this problem as well and I believe what I did wrong was when I created the iCloud container ID I manually typed in the "iCloud" at the start of the bundle ID. For example I created the iCloud container ID as "iCloud.com.myBundleName.myCompany".

Xcode automatically adds the "iCloud" to the beginning of the name you type, so I believe what it was seeing was "iCloud.iCloud.com.myBundleName.myCompany" and thus giving the error.

Try just typing "com.whateverBundleName.whateverCompany" and Xcode will add the iCloud at the beginning automatically. That solved the error for me.

The bug still exists now, I am using Xcode 15.2, and I switched to another container the problem is solved, Does it so damn hard for Apple to fix this annoying bug?

I had the same issue, the bug still exists. But you can go to "Signing & Capabilities" in Xcode. Uncheck the "CloudKit" button under the iCloud section, save the project and check the button again. Then choose your container again. That fixes the issue. Additionally make sure that the name of your model doesn't already exist in your container as a RecordType to prevent unexpected errors again.

Invalid Bundle ID for container
 
 
Q