9

If I try subscribe to CloudKit with this code:

    NSPredicate *truePredicate = [NSPredicate predicateWithValue:YES];
    CKSubscription *itemSubscription = [[CKSubscription alloc] initWithRecordType:RecordType
                                                                        predicate:truePredicate
                                                                          options:CKSubscriptionOptionsFiresOnRecordCreation | CKSubscriptionOptionsFiresOnRecordUpdate | CKSubscriptionOptionsFiresOnRecordDeletion];


    CKNotificationInfo *notification = [[CKNotificationInfo alloc] init];
    notification.alertBody = @"Item Added/Updated/Deleted!";
    itemSubscription.notificationInfo = notification;

    [self.publicDatabase saveSubscription:itemSubscription completionHandler:^(CKSubscription *subscription, NSError *error) {
        if (error) {
            // In your app, handle this error appropriately.
            NSLog(@"An error occured in %@: %@", NSStringFromSelector(_cmd), error);
        } else {

            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:subscription.subscriptionID forKey:kSubscriptionID];
            [defaults synchronize];
        }
    }];

I sometimes get this error:

CKError 0x17558460: "Server Rejected Request" (15/2000); server message = "Internal server error"; uuid = B89DE7A4-9D22-42BC-9CD4-4330F3FE04EF; container ID = "iCloud.com.app.testApp"

or

CKError 0x14fb3510: "Service Unavailable" (6/2022); server message = "failed up to install schema, CAS failed"; uuid = F562D1AD-B40E-4842-A5EA-2A5F800C18F2; container ID = "iCloud.com.app.testApp"

Anybody know how to fix that? Can I do something with my code? Is this Apple problem and I can't do anything? Thanks.

János
  • 32,867
  • 38
  • 193
  • 353
Mikhail S
  • 3,338
  • 3
  • 21
  • 34
  • I've had the first error before, where it just appear suddenly for a few hours, and went away after that. That was problem with Apple's server. But if the problem does not go away, then it is probably yours. – honcheng Sep 29 '14 at 09:50
  • for the second error, have you already created the record type before you subscribe to it? – honcheng Sep 29 '14 at 09:51
  • yes, I have record type. – Mikhail S Sep 29 '14 at 10:23

3 Answers3

3

I just recently got a similar error, and was able to resolve it by toggling CloudKit in the project's capabilities. Once I reset that CloudKit permission, all seemed to work just fine.

adam.wulf
  • 2,149
  • 20
  • 27
  • I was having the same issue and while a new container did not fix it, this suggestion appeared to fix it. However, the problem has come back a few times. I might try creating a clean Xcode project. – coping Jan 28 '16 at 02:05
  • This also solved a somewhat similar CKInternalErrorDomain complaint about the schema not matching with the server. – Thunk Nov 06 '16 at 16:28
1

I had the exact same problem. I ended up changing the containers entirely (goto project target -> Capabilities -> specify custom containers -> enter a new container ID). It worked perfectly after.

ninjaneer
  • 6,951
  • 8
  • 60
  • 104
1

I had exact error : "Server Rejected Request" (15/2000); server message = "Internal server error" as result of CKModifySubscriptionsOperation.

Strange thing that testing the subscription with iPad was Ok. but, subscription from iPhone didn't work.

Fixed it by changing the NSPredicate format:

1- old format (not working)

1-1:

let predicate = NSPredicate(format: "rate >= 0")

1-2:

let x = 0 as! NSNumber

let predicate = NSPredicate(format: "rate >=", x)

2- New predicate format (fixed the issue):

let predicate = NSPredicate(format: "rate >=", NSNumber(integerLiteral: 0))

AAH
  • 11
  • 2