Invalid bundle ID for container

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:

  1. Creating a new container
  2. Unselecting and selecting the container in signing & capabilities
  3. Unselecting and selecting the container in App ID Configuration
  4. 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

The same error was discussed here. Please follow the steps described in Configure CloudKit in your project to debug. If the issue is still there after that, please share your feedback report ID that contains the mentioned information. Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Invalid bundle ID for container
 
 
Q