10

I'm trying to save a record CloudKit but I'm getting the following error from cloudkit:

error saving record este es error: Error saving record <CKRecordID: 0x7fef15b5d2a0; 2:(_defaultZone:__defaultOwner__)> to server: WRITE operation not permitted

Here is how I'm trying to save the record:

[publicDatabase saveRecord:recordContent completionHandler:^(CKRecord *record, NSError *error){

if (!error)
{
    NSLog(@"saved!!!");

}
else
{
    if ([[error.userInfo valueForKey:@"ErrorDescription"] isEqualToString:@"record to insert already exists"])
    {
        NSLog(@"record already exist %@",[error.userInfo valueForKey:@"ErrorDescription"]);

    }

    NSLog(@"error saving record : %@",error.localizedDescription);
}
}];

But before had I check if cloudkit is available:

[myContainer accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error)
     {
         NSLog(@" no error but status %ld",accountStatus);

         if (((accountStatus == 3) || (accountStatus == 2)) && (!error))
         {
             NSLog(@" no error but status %ld",accountStatus);


             //            typedef NS_ENUM(NSInteger, CKAccountStatus) {
             //                /* An error occurred when getting the account status, consult the corresponding NSError */
             //                CKAccountStatusCouldNotDetermine                   = 0,
             //                /* The iCloud account credentials are available for this application */
             //                CKAccountStatusAvailable                           = 1,
             //                /* Parental Controls / Device Management has denied access to iCloud account credentials */
             //                CKAccountStatusRestricted                          = 2,
             //                /* No iCloud account is logged in on this device */
             //                CKAccountStatusNoAccount                           = 3,
             //
             //        }
         }


         if (error)
         {
             NSLog(@" accountStatus error %@",error);

         }
     } ];

Where I'm getting status 1, meaning CKAccountStatusAvailable.

Any of you knows why this is happening it has been working fine until the last record or any of you knows a work around this?

I'll really appreciate your help.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2924482
  • 8,380
  • 23
  • 89
  • 173
  • Are you saving a new record or updating an existing record? If you are updating, then was that record also created by you (the same apple id). If not, then go to the iCloud dashboard and set the permissions to that recordType that all users may update. – Edwin Vermeer Aug 26 '15 at 09:37
  • Thanks for pointing out that you need to set permissions to allow deleting public records. – Peter B. Kramer Sep 02 '15 at 16:46

4 Answers4

31

You need to set permission to allow a user to write (or delete) a record created by someone else. You do that in the Development Environment, under Schema, Record Types, select the specific record, then over on the right there is a drop down menu labelled Security. Grant to the Role ' Authenticated' the right to Read and Write. Then deploy to Production.

Peter B. Kramer
  • 16,385
  • 1
  • 16
  • 20
7

This was moved in the latest CloudKit, took me a while to track it down.

Beware, this isn't instant, it takes a while for these changes to propagate after saving them. Come back later and refresh the page to see if they've been applied. enter image description here

enter image description here

If you are still getting this error after setting these permissions and letting them propagate then it's likely that your iCloud Login in Simulator is messed up. Logging out of iCloud and logging in again fixed this for me.

Community
  • 1
  • 1
William T.
  • 12,831
  • 4
  • 56
  • 53
  • After "deploy schema to production" and some times waiting, I'm still have issue with set roles in production environment - all checkboxes are empty and it look like fields are disabled. What am I doing wrong? – zslavman Jun 27 '20 at 12:33
2

I spent 2 days for "Permission failure (10/2007)". All permissions and security roles was set as in William.T picture. Relogin into iCloud doesn't got any results. The snag was in one small setting (not documented by Apple) - it was switcher "iCloud Drive" which located in Settings/[your account]/iCloud/iCloud Drive on my device. Apple's documentation is terrible! no one will return me 2 days spent. Hope this helps someone with the same problem.

zslavman
  • 401
  • 5
  • 11
0

In my case i forgot to do a basic check: make sure you're logged in with your Apple ID and make sure the iCloud checkmark for your application is turned on. This can happen especially using Simulators.

smukamuka
  • 1,442
  • 1
  • 15
  • 23