My app is written in SwiftUI using Cloudkit to store records from Core Data. I'm able to get records using @FetchRequest
to populate a list. Now I want to get the current user's iCloud ID and compare it to another global ID, but I'm having issues with fetchUserRecordID
...
I'm able to see user records when looking at Cloudkit Dashboard's Users
record type. But every time the code below runs I get the following error: "Couldn't get container configuration from the server for container "iCloud.com.my_container_name""
I'm running Xcode 12.2 Beta 4
ContentView.swift
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
init() {
isCreator()
}
var body: some View {
Text("Hello World")
}
func isCreator() {
CKContainer.default().fetchUserRecordID(completionHandler: { (recordId, error) in
guard let record = recordId, error == nil else {
print("Error: \(error!.localizedDescription)")
return
}
print("Found record")
// Now do something with record...
})
}
} // end ContentView
Use CKContainer(identifier: "iCloud.name_of_your_container")
instead of CKContainer.default()
My issue was that I named my Cloudkit container testapp
and my app's bundle id was com.my_team_name.testapp
. When running Cloudkit queries, I kept getting this error:
Couldn't get container configuration from the server for container "iCloud.com.my_team_name.testapp"
After looking at the Cloudkit Dashboard I realized that my container's name was literally only "testapp."
Once I changed my code to CKContainer(identifier: "iCloud.testapp")
, it worked just fine.