CK订阅和生产容器

CKSubscriptions and production container

您好,我正在尝试创建 CKSubscription,我使用此代码:

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)
    }
}

问题是这段代码只能在模拟器上运行,当我在真实设备上运行应用程序时,我得到这个错误:

attempting to create a subscription in a production container.

我该如何解决这个问题?

我遇到了完全相同的问题,解决方案很简单,但不是很直观。 在开发模式下,让应用创建您需要的订阅。将数据库部署到生产环境。 在生产环境中测试您的应用程序,您会看到它现在可以创建您所做的订阅。 希望有用