Cloudkit: “ error saving record WRITE operation not permitted”

拈花ヽ惹草 提交于 2019-12-08 15:40:20

问题


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.


回答1:


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.




回答2:


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.

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.



来源:https://stackoverflow.com/questions/32192968/cloudkit-error-saving-record-write-operation-not-permitted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!