Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudkit: " error saving record WRITE operation not permitted"

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.

like image 420
user2924482 Avatar asked Aug 24 '15 22:08

user2924482


3 Answers

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.

like image 180
Peter B. Kramer Avatar answered Oct 24 '22 08:10

Peter B. Kramer


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.

like image 45
zslavman Avatar answered Oct 24 '22 08:10

zslavman


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.

like image 20
William T. Avatar answered Oct 24 '22 09:10

William T.