5

I do not quite understand the information about subscriptions. I have Private Database. There is a table to which I create a subscription. If I subscribe to two devices under one iCloud account, errors occur: Subscribed with error:

CKError 0x165c6ac0: "Server Rejected Request" (15/2032); server message = "subscription is duplicate of 'C6051A24-2DB5-47EA-98D2-7D8786AA6D3B'"; uuid = 48AC7472-006A-4FD7-84A9-DB342C83C199; container ID = "iCloud.com. *. *"

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


CKNotificationInfo *notification = [[CKNotificationInfo alloc] init];
notification.shouldSendContentAvailable = YES;

notification.alertLocalizationKey = @"";
notification.shouldBadge = NO;

itemSubscription.notificationInfo = notification;

[self.privateDatabase saveSubscription:itemSubscription completionHandler

Maybe I'm doing something wrong? What I need to do to both devices receive notification of subscriptions?

Edited:

Also. I create only one subscription. If I use method fetchAllSubscriptionsWithCompletionhandler I see 3-4 of the subscriptions per table. But it's weird because I create only one. And when I receive the notification, I see more notifications than it should be.

Mayur Karmur
  • 2,119
  • 14
  • 35
Mikhail S
  • 3,338
  • 3
  • 21
  • 34
  • 1
    Try to reset the Database and start over – harryhorn May 14 '15 at 09:43
  • Thanks harryhorn, now these subscriptions anymore. – Mikhail S May 15 '15 at 04:22
  • harryhorn, Now again there was the same problem. Do not receive the notification due to a hung on the side of iCloud subscriptions that I can't remove. Only Reset Development Environment helps. Why this happens? It's Apple side bug? – Mikhail S Jul 02 '15 at 09:14

1 Answers1

6

A subscription is per Database. So if you want to receive notifications to multiple users on a database it is enough to create it once. You are getting an error because you are creating the same subscription (same subscription ID) twice on the same database. Simply make sure you create it only once. You can fetch subscriptions to check if it has already been created or not. Harry

harryhorn
  • 892
  • 6
  • 8
  • If I create a subscription, it does not matter what device, then the registration of the notification, both devices will get a change? – Mikhail S May 14 '15 at 07:53
  • Yes, both devices will get the change. Try it. – harryhorn May 14 '15 at 09:24
  • Actually, I am not sure and need to check this again. But in any case, it seems like you are registering twice with the same subscription ID. You do not have to create a subscription with an ID, so try that first, and you may need to subscribe from each client. Sorry – harryhorn May 14 '15 at 09:55
  • 1
    This is very confusing for me because I receive this same error, but the subscriptionIDs aren't the same. Error saving record subscription with id BA3B7883-9D4C-4A5A-9F03-52987466E332 to server: subscription is duplicate of 'EC4279FA-2814-4D66-9B03-7014FADF1278. So how am I supposed to check for duplicates? – Scooter Dec 08 '16 at 03:12
  • 1
    Its 2017 and i still see this. I just ignore this error & it works fine. App needs to subscribe once during its life cycle but even then this error ocurs. – Vikram Rao Nov 01 '17 at 11:29
  • 2
    It's not per database... from the apple docs: CloudKit subscriptions are per-user, which means your app needs to create subscriptions for each and every user that should receive push notifications. Logging in CloudKit Dashboard with your account and seeing subscriptions there doesn’t mean all users have them ... – kevinius Feb 18 '18 at 16:27