Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudKit subscription sometimes does not work

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.

like image 883
Mikhail S Avatar asked Sep 29 '14 05:09

Mikhail S


People also ask

Does Apple use CloudKit?

Overview. The CloudKit Database app is a web-based tool for developers to manage their iCloud containers. You can sign in to the CloudKit Database app through the Apple Developer web portal or through the CloudKit Console at https://icloud.developer.apple.com/.

What is CloudKit on Iphone?

CloudKit is a framework that lets app developers store key-value data, structured data, and assets in iCloud. Access to CloudKit is controlled using app entitlements. CloudKit supports both public and private databases.

What is CloudKit container?

Container. A CloudKit. Container object provides access to an app container, and through the app container, access to its databases. It also contains methods for authenticating and fetching users.

What is CloudKit Mac?

CloudKit is an integrated macOS and iOS API that functions as a backend as a service (BaaS). CloudKit is the framework that powers iCloud on iOS, macOS and on the web.


2 Answers

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.

like image 82
adam.wulf Avatar answered Oct 10 '22 06:10

adam.wulf


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.

like image 29
ninjaneer Avatar answered Oct 10 '22 07:10

ninjaneer