SaveRecord error when user hasn't checked the iCloud drive checkbox

Running into problems? This is a good place to get technical assistance for anything that isn't considered a bug.
downstroy
Posts: 1
Joined: Mon Jul 05, 2021 12:38 pm

SaveRecord error when user hasn't checked the iCloud drive checkbox

Post by downstroy »

Hi,

I am trying to save a record in the public database of the application, but if the user hasn't checked the Iclou drive checkbox in their profile settings, the record fail to save with this error :

Code: Select all

 CloudKit access was denied by user settings
Eden.Logging.EdenLogger:LogGeneric(Verbosity, String, Object)
System.Action`2:Invoke(T1, T2)
System.Threading.SendOrPostCallback:Invoke(Object)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()
The permission for the writing/ reading/ editing of record is default (_world - Read, _icloud - Create, _creator - Write).

From what I have gathered it seems to be a bug in cloudkit that requires this checkbox to be on to create a record in cloudkit? Could you confirm that?

As a side question, how to handle this error (I try to save the record again when starting the app). For now I am doing this:

Code: Select all

database.SaveRecord(record, async (r, error2) => {
	if (error2 != null)
	{
		switch (error2.Code)
		{
			// NSCloudSharingConflictError (record already exists, no problem)
			case 5123L:
			break;
			// In any other case, display the recovery suggestion and log the error
			default:
			// do other things
			break;
		}
		return;
	}
But I am not sure what the error code would be here when the record already exists?

Thanks!

admin
Site Admin
Posts: 49
Joined: Thu Mar 19, 2020 8:52 pm

Re: SaveRecord error when user hasn't checked the iCloud drive checkbox

Post by admin »

I believe that is the correct behavior. The iCloud Drive permission also controls public database access.

admin
Site Admin
Posts: 49
Joined: Thu Mar 19, 2020 8:52 pm

Re: SaveRecord error when user hasn't checked the iCloud drive checkbox

Post by admin »

As to the other question. There are two ways to solve this. But first some background information:

CloudKit's is attempting to prevent you from clobbering an already existing record. It sees that the record you've made on the client was not made from the most recent version of the record that exists on the server, and it's default policy is to prevent you from overwriting it.

Here are the two solutions:
1. If you know the record exists already, fetch the record from the database and modify it, the re-save it. CloudKit will verify that you used the most recent version of the record and the save will succeed.
2. (what most users end up doing) Change the save policy of cloud-kit to allow you to completely overwrite the previous record. In order to do this, you'll need to use the CKModifyRecordsOperation instead of the convenience API apple provides. See the property "save policy" here:

https://developer.apple.com/documentati ... guage=objc

Post Reply