CloudKit - "Invalid bundle ID for container"
Asked Answered
P

7

12

I've just create a project in Xcode 9 beta 6 and add this code:

let privateDB = CKContainer.default().privateCloudDatabase
let greatID = CKRecordID(recordName: "GreatPlace")
let place = CKRecord(recordType: "Place", recordID: greatID)

privateDB.save(place) { (record, error) in
        if error != nil {
            let er = (error as! CKError).errorUserInfo
            print("Error: \n")
            print("CKErrorDescription: \(er["CKErrorDescription"]!)\n")
            print("ContainerID: \(er["ContainerID"]!)\n")
            print("NSDebugDescription: \(er["NSDebugDescription"]!)\n")
            print("NSUnderlyingError: \(er["NSUnderlyingError"]!)\n")
            print("NSLocalizedDescription: \(er["NSLocalizedDescription"]!)\n")
            print("ServerErrorDescription: \(er["ServerErrorDescription"]!)\n")
        }
        if record != nil {
            print("record: \(record!)")
        }
 }

and add this capabilities:

enter image description here

and when I run the code I receive this error message:

enter image description here

What I am doing wrong ?

Propagable answered 10/9, 2017 at 18:31 Comment(0)
L
15

There was a bug causing some associations to be missed. That bug has been fixed and we automatically fixed the container/app associations that were broken during that time.

If for some reason you still need to redo an association you can either use the Capabilities pane in Xcode or use developer.apple.com -> Certificates, Identifiers & Profiles -> App IDs -> pick the ID -> Edit -> Edit under iCloud -> check the box for the container to disassociate, save, then re-associate.

If you're still stuck please email cloudkit[at]apple.com

Landing answered 14/9, 2017 at 2:35 Comment(10)
Hi Dave, thanks for your answer. Actually, every new project I tried to create using CloudKit has the same problem. What should I do ? Send only the bundle ID and Container ID I'm currently working on ? Regards !Propagable
I have the same error, I tried your solution but it doesn't work. Just nothing changed :(Sonorant
Just encountered the same issue with Xcode 12.5. Playing with the Capabilities pane in Xcode didn't help, but the 2nd solution (reassociating via developer.apple.com) did. Of course I had to regenerate the provisioning profiles for the app after editing the App ID.Chickenhearted
I've set up iCloud on a few projects without seeing this issue. However I recently encountered it. I noticed a "iCloud Container Assignment" button; the container I set up in Xcode was not associated there.Kaffiyeh
After many frustrating hours I came to this answer. What worked for me is: 1. deselect the container on Xcode, 2. deselect container on developer.apple.com (and save), 3. select container again on website, 4. regenerate profiles and finally 5. select container on Xcode.Bonspiel
@vauxhall thanks for your solution, this worked! Dave, you and the team might want to check this.Conjugal
@vauxhall's solution worked for me, but since I am having Xcode manage signing, I had to turn off "Automatically Manage Signing", then follow the steps, and then turn it back on, which seemed to re-created the auto-generated profile.Ditchwater
@Ditchwater for me it worked even after the auto-generate profile. Seems like after it manages to associate it continues to do so after re-creations..Bonspiel
For me just resetting the iCloud capability was not enough. But everything worked after I removed the entire App ID (it was managed by XCode)Stairway
Some years later I just had this issue with Xcode 13Superintend
F
4

Thanks to Dave Browning, this is based on his answer.

Following worked for me:

Check the container id
  • Check the container id used for initialisation of CKContainer
  • Note: If you are using NSPersistentCloudKitContainer we wouldn't be using the container id directly would be picked automatically from the entitlements file.

Try to disable and enable iCloud on the App ID

Disable and Enable iCloud on App ID

  1. Go to https://developer.apple.com and sign in
  2. Select Certificates, Identifiers & Profiles
  3. Select Identifiers (App IDs)
  4. Edit App ID for the app
  5. Uncheck iCloud
  6. Save
  7. Check iCloud
  8. Quit Xcode and Clear DerivedData
  9. Run app
Forwards answered 17/8, 2022 at 5:56 Comment(2)
This worked. The problem was on Certificates side. And automatic Xcode sign didn't work, since I'm not the admin in the team.Aporia
I had to add a step between 8 and 9 — delete app from test deviceAduwa
S
1

In my case, I had to delete the app from the device, and initialize it again. Then it worked again.

Sirois answered 14/6, 2023 at 12:21 Comment(0)
P
0

My friend and I are having the same issue. We made 2 different projects and both of them had the same error message "Invalid bundle ID for container" which is CKError case 10 .

We are calling our fetch function to get the default "Users" record in the viewDidLoad.

func fetchWorkoutCompleted(completion: @escaping (Error?) -> Void = { _ in }) {
    cloudKitManager.fetchRecord(ofType: "Users", sortDescriptors: nil) { (records, error) in
        if let error = error {
            print(error.localizedDescription)
            completion(error)
            return
        }
        guard let records = records else { completion(nil); return }
        completion(nil)
    }
}
Paries answered 12/9, 2017 at 15:35 Comment(2)
Do you think it could be an environment problem?Propagable
Yeah, it might have something to do with the Apple's Keynote. I have several small cloudKit projects from the past that are working fine.Paries
A
0

Using Xamarin.IOS, I had to select manual provisioning rather than automatic provisioning in the info.plist file.

Alizaalizarin answered 8/4, 2021 at 5:20 Comment(0)
F
0

Had the same issue. what worked for me was changing the iCloud group name.

  • Before it was something like this: iCloud.com.companyName.appName.randomString

  • After changing to: iCloud.com.companyName.randomString it started working and synchronising.

If after adding the new container it's red press the refresh button(from under the groups) and try a clean install on your phone and it should work

Farlie answered 27/3, 2022 at 19:31 Comment(0)
G
0

For me, the problem is that for creating a container I use CKContainer.default(). I have two different bundle identifier (debug and release) and CKContainer.default() will take the CK container identifier to be the same as the bundle identifier of the app. When I change for creating a container to use CKContainer(identifier: “my_cloudkit_identifier”) I could use the same CK container for the debug and release.

Gober answered 20/10, 2023 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.