Reputation: 105
I noticed that when testing my cloudkit app in the simulator or physical device that I can only save records with my alt account and not the dev account that I used to make the app/container. When I go to save I get the error:
Error saving record <CKRecordID: 0x9t83ecb31790; recordName=8AB667FA-0D8F-4B72-8B90-C694AB960EFF, zoneID=_defaultZone:defaultOwner> to server: CREATE operation not permitted
The specific error code is 10 when running
if let error = error as? CKError { print(error.errorCode) }
Which indicates a permissions problem. All the security roles are correct in the cloudkit dashboard. I confirmed the user is authenticated with cloudkit on all accounts with
CKContainer.default().accountStatus { (accountStatus, error) in
switch accountStatus {
case .available:
print("iCloud Available")
case .noAccount:
print("No iCloud account")
case .restricted:
print("iCloud restricted")
case .couldNotDetermine:
print("Unable to determine iCloud status")
}
}
It doesn't work on the Apple Reviewer's end either and they have rejected my app for this error. That means its not just my Dev account that doesn't work, it seems to be everything except my alt. Which seems pretty strange.
Here is my save code:
static func saveUser(user: UserElement, completion: @escaping (Result<UserElement, Error>) ->
()) {
let itemRecord = CKRecord(recordType: "userInfo")
itemRecord["uniqueID"] = user.bossID as CKRecordValue
itemRecord["screenName"] = user.screenName as CKRecordValue
itemRecord["shareCode"] = user.shareCode as CKRecordValue
itemRecord["subscribedBosses"] = user.subscribedBosses as CKRecordValue
let container = CKContainer(identifier: "iCloud.Caz4Short.WatChaDoin")
container.publicCloudDatabase.save(itemRecord) { (record, err) in
DispatchQueue.main.async {
if let err = err {
print("error on run")
completion(.failure(err))
return
}
guard let record = record else {
print("record")
completion(.failure(CloudKitHelperError.recordFailure))
return
}
let id = record.recordID
guard let boss = record["uniqueID"] as? String else {
print("record ID")
completion(.failure(CloudKitHelperError.recordIDFailure))
return
}
guard let name = record["screenName"] as? String else {
print("screenname")
completion(.failure(CloudKitHelperError.castFailure))
return
}
guard let bossCode = record["shareCode"] as? String else {
print("Code")
completion(.failure(CloudKitHelperError.castFailure))
return
}
guard let subs = record["subscribedBosses"] as? [String] else {
completion(.failure(CloudKitHelperError.castFailure))
return
}
let element = UserElement(recordID: id, bossID: boss, screenName: name, shareCode: bossCode, subscribedBosses: subs)
completion(.success(element))
}
}
}
Upvotes: 0
Views: 136
Reputation: 105
It was a bug with CloudKit. Sometimes the container can be broken on creation apparently.
I was able to fix it by creating a new container in Xcode (on the config screen for your app) and unchecking the old one. Then I configured the new container from scratch, adding all the data types and configuring the security roles (roles take like 5min to kick in so just keep checking/trying).
Upvotes: 0