Hi. I am having this error when trying to write to CloudKit public database.
<CKError 0x600000dbc4e0: "Permission Failure" (10/2007); server message = "Invalid bundle ID for container";
On app launch, I check for account status and ensure that the correct bundle identifier and container is being used. When the account status is checked, I do get the correct bundle id and container id printed in the console but trying to read or write to the container would throw that "Invalid bundle ID for container" error.
private init() {
container = CKContainer.default()
publicDB = container.publicCloudDatabase
// Check iCloud account status
checkAccountStatus()
}
func checkAccountStatus() {
print("🔍 CloudKit Debug:")
print("🔍 Bundle identifier from app: (Bundle.main.bundleIdentifier ?? "unknown")")
print("🔍 Container identifier: (container.containerIdentifier ?? "unknown")")
container.accountStatus { [weak self] status, error in
DispatchQueue.main.async {
switch status {
case .available:
self?.isSignedIn = true
self?.fetchUserID()
case .noAccount, .restricted, .couldNotDetermine:
self?.isSignedIn = false
self?.errorMessage = "Please sign in to iCloud in Settings to use this app."
default:
self?.isSignedIn = false
self?.errorMessage = "Unknown iCloud account status."
}
print("User is signed into iCloud: \(self?.isSignedIn ?? false)")
print("Account status: \(status.rawValue)")
}
}
}
I have tried:
Creating a new container
Unselecting and selecting the container in signing & capabilities
Unselecting and selecting the container in App ID Configuration
I used to have swift data models in my code and read that swift data is not compatible with CloudKit public data so I removed all the models and any swift data codes and only uses CloudKit public database.
let savedRecord = try await publicDB.save(record)
Nothing seems to work. If anyone could help please?
Rgds,
Hans
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Cloud and Local Storage
CloudKit Console