9

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 ?

Sebastian
  • 6,154
  • 5
  • 33
  • 51

6 Answers6

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

Dave Browning
  • 1,256
  • 7
  • 7
  • 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 ! – Sebastian Sep 14 '17 at 15:43
  • 1
    I have the same error, I tried your solution but it doesn't work. Just nothing changed :( – Farras Doko Oct 23 '20 at 13:50
  • 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. – Vadim Belyaev May 31 '21 at 23:17
  • 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. – James Oct 01 '21 at 11:26
  • 5
    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. – vicegax Nov 28 '21 at 16:59
  • @vauxhall thanks for your solution, this worked! Dave, you and the team might want to check this. – Jordi Bruin Jan 15 '22 at 15:23
  • @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. – coping Apr 21 '22 at 02:39
  • @coping 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.. – vicegax Apr 21 '22 at 08:25
  • 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) – codingFriend1 Jun 23 '22 at 18:04
  • 3
    Some years later I just had this issue with Xcode 13 – onmyway133 Jul 22 '22 at 17:09
1

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
Nico S.
  • 3,056
  • 1
  • 30
  • 64
user1046037
  • 16,755
  • 12
  • 92
  • 138
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)
    }
}
pcnick13
  • 114
  • 5
0

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

Adam B
  • 3,662
  • 2
  • 24
  • 33
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

Silviu St
  • 1,810
  • 3
  • 33
  • 42
0

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

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116