Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKSubscriptions and production container

Tags:

swift

icloud

Hi I'm trying to create a CKSubscription, I use this code:

func setupCKSubscriptions(){

    if NSUserDefaults.standardUserDefaults().boolForKey("sub") == false{

    let subscription = CKSubscription(recordType: "Quadri", predicate: NSPredicate(value: true), options: .FiresOnRecordCreation)

    let notificationInfo = CKNotificationInfo()
    notificationInfo.alertLocalizationKey = NSLocalizedString("NEW_Q", comment: "")
    notificationInfo.shouldBadge = true

    subscription.notificationInfo = notificationInfo

    CKContainer.defaultContainer().publicCloudDatabase.saveSubscription(subscription) { (subscription, errore) -> Void in

        if errore == nil{

            NSUserDefaults.standardUserDefaults().setBool(true, forKey: "sub")
            NSUserDefaults.standardUserDefaults().synchronize()
            let alert = UIAlertController(title: "Ok", message: "", preferredStyle: .Alert)
            self.presentViewController(alert, animated: true, completion: nil)

        }else{

            print(errore?.localizedDescription)
            let alert = UIAlertController(title: "Errore", message: errore?.localizedDescription, preferredStyle: .Alert)
            self.presentViewController(alert, animated: true, completion: nil)
        }
    }
    }else{

        let alert = UIAlertController(title: "Errore", message: "", preferredStyle: .Alert)
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

The problem is that this code only works on the simulator, when I run the app on a real device I get this error:

attempting to create a subscription in a production container.

How can I fix this?


1 Answers

I had exactly the same problem and the solution is easy, BUT NOT VERY INTUITIVE. In development mode let the app create the subscription(s) you need. Deploy database to production. Test your app in production and you'll see it can now create the subscription you have made. Hope it works

like image 80
Lars Christoffersen Avatar answered Dec 16 '25 21:12

Lars Christoffersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!