agilebits / AgileCloudSDK

AgileCloudSDK is our CloudKit JS implementation of the CloudKit framework. It is used in 1Password for Mac.
MIT License
237 stars 11 forks source link

Saving test CKRecord to public database doesn't work (error: atomic operations not supported) #24

Open daveymcgav opened 8 years ago

daveymcgav commented 8 years ago

Trying to save a new CKRecord to the public database results in this error:

Error Domain=CKErrorDomain Code=11 "(null)" UserInfo={serverErrorCode=BAD_REQUEST, _ckErrorCode=BAD_REQUEST, reason=atomic operations not supported in default zone, uuid=600a6b81-71e1-4114-9a26-96e66d3ac0a8}

Code (that works with regular CloudKit.framework):

` CKContainer *container = [CKContainer containerWithIdentifier:@"iCloud.com.loopware.iFlash"];

    [container accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error)
     {
         if (accountStatus == CKAccountStatusAvailable)
         {
             NSLog(@"iCloud account available!");

             CKDatabase *publicDatabase = [container publicCloudDatabase];

             CKRecord *testRecord = [[CKRecord alloc] initWithRecordType:@"Decks"];
             [testRecord setObject:@"Testing Yay" forKey:@"name"];

             [publicDatabase saveRecord:testRecord completionHandler:^(CKRecord *record, NSError *error)
              {
                  NSLog(@"Saved record: %@  withError: %@", record, error);
              }];
         }
         else
         {
             NSLog(@"iCloud account unavailable :(.");
         }
     }];

`

kevinbhayes commented 8 years ago

Since the public database doesn't support atomic operations, a change will need to be made in the saveRecord:completionHandler: method in CKDatabase. It should check its isPublic property and if it is YES, then set the atomic property on the CKModifyRecordsOperation to NO right after it is created.