cloudkit subscription error

i am trying to create subscriptions but i see some weird error popping out.

I have tried to search google and stackoverflow without any luck

Can someone help me please?

Code is the following



    func SottoscrizioneAccessori()->Void
    {
        if UserDefaults.standard.bool(forKey: "SUBACCESSORI_\(Manager.AI.StatoAttuale.NodoAI.PIVA)") == false
        {
            
            let predicate=NSPredicate(format: "RefAzienda = %@", Manager.AI.StatoAttuale.NodoAI.PIVA)
            let subscription=CKQuerySubscription(recordType: "CKAccessori",
                                                 predicate:predicate,
                                                 subscriptionID: "CKSUBACCESSORI",
                                                 options: [.firesOnRecordUpdate, .firesOnRecordCreation])
            let nInfo=CKNotificationInfo()
            
            nInfo.alertBody = "Accessori Aggiornati"
            nInfo.shouldBadge=false
            
            subscription.notificationInfo = nInfo
            Manager.AI.pubDB.save(subscription, completionHandler: { (retRecord, error) in
                if error != nil
                {
                    print("SUB_ACCESSORI - sottoscrizione fallita con errore \(error?.localizedDescription ?? "-err-")")
                }
                else
                {
                    print("SUB_ACCESSORI - sottoscrizione creata con successo")
                    UserDefaults.standard.set(true, forKey: "SUBACCESSORI_\(Manager.AI.StatoAttuale.NodoAI.PIVA)")

                }
            })
        }
    }

the database is the development one (tried also to force the production one and the error was that i cannot create subscription on production container


The error in the console is:

SUB_ACCESSORI - sottoscrizione fallita con errore Error saving record subscription with id CKSUBACCESSORI to server: Deployed schema UUID does not match supplied parent UUID.


the development database is already deployed in production... everything is "correct" (name of recordtype, fields, etc.etc.)...

i am not able to find this kind of error anywhere...

someone?

Accepted Reply

I have found the problem

So for everyone else here who may find this kind of error: NEVER save multiple subscription without waiting the previous one has completed its cycle.

Now i wait for each single subscription and everything is fine.

  • Hi, I know this is an old issue but I've experienced the same behaviour and this is the only mention of it on the web. I've resolved the issue by using different functions for creating my create and update subscriptions, and this works every time but the solution feels clunky. How did you implement the wait for each subscription to finish? was this via async / await?

Add a Comment

Replies

funny thing is that i have several subscription, all with the same type of code but different recordtype name, and some fails, others are successfull, but from one run to another (erasing the subscription from dashboard) the successful are not always the same...

I have found the problem

So for everyone else here who may find this kind of error: NEVER save multiple subscription without waiting the previous one has completed its cycle.

Now i wait for each single subscription and everything is fine.

  • Hi, I know this is an old issue but I've experienced the same behaviour and this is the only mention of it on the web. I've resolved the issue by using different functions for creating my create and update subscriptions, and this works every time but the solution feels clunky. How did you implement the wait for each subscription to finish? was this via async / await?

Add a Comment