我试图保存一个CloudKit记录,但是我从cloudkit得到了以下错误:
error saving record este es error: Error saving record <CKRecordID: 0x7fef15b5d2a0; 2:(_defaultZone:__defaultOwner__)> to server: WRITE operation not permitted
这是我尝试保存记录的方法:
[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);
}
}];
但在此之前,我需要检查CloudKit是否可用:
[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);
}
} ];
我在获取状态1,即CKAccountStatusAvailable。
你们有谁知道为什么会发生这种情况吗?它一直运行得很好,直到最后一个记录或任何人都知道解决方法吗?
非常感谢你们的帮助。