16

Anyone know what could be causing this error which is returned in the query block below:

<CKError 0x7f8d5ba27a10: "Internal Error" (1/4000); "Couldn't send a valid signature">

Here is my code snippet:

CKContainer *container = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [container publicCloudDatabase];

//CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:container] publicCloudDatabase];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"doctorName = %@", @"Dr. Harry White"];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"WellnessTest" predicate:predicate];

[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error)
{
    if (error)
    {
        // Error handling for failed fetch from public database
        NSLog(@"ERROR: %@", error.description);
    }
    else
    {
        // Display the fetched records
        NSLog(@"Results: %@", results.description);
    }
}];
croc_hunter
  • 285
  • 3
  • 12

2 Answers2

35

On the iPhone/iPad simulator go to Settings > iCloud and then log in using your Apple ID.

Dave Wood
  • 13,143
  • 2
  • 59
  • 67
Holmes
  • 529
  • 1
  • 6
  • 15
  • Great thanks that solved my issue. Didnt know i could login to iCloud through the simulator. – croc_hunter Apr 28 '15 at 01:02
  • 12
    shouldn't you be able to query the public database without logging in? – Andy Jul 26 '15 at 08:38
  • @Andy exactly what I was thinking. – StuFF mc Feb 20 '16 at 14:33
  • 5
    A comment in http://stackoverflow.com/questions/35321975/couldnt-send-a-valid-signature-error-when-using-cloudkit-without-icloud-accou explains why this is needed. – Keller Mar 26 '16 at 13:50
  • 2
    @holmes Eternal gratitude to you, O Master :) – Jean Le Moignan May 04 '16 at 18:05
  • 6
    Anyone have any idea on this when you ARE logged into CloudKit (Simulator). This is with Xcode 9. My simulator is logged in to CloudKit (and my check I do earlier to make sure they are logged in passes) but when I try and do a fetch I get this error. – chadbag Oct 24 '17 at 02:13
1

If you're testing your app against CloudKit's Production environment, you may still have this error even if you have signed into iCloud on the simulator. In this case, running your app on a device would fix the error.

CodeBrew
  • 6,457
  • 2
  • 43
  • 48