您好,我正在尝试创建一个 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.
我该如何解决这个问题?
最佳答案
我遇到了完全相同的问题,解决方案很简单,但不是很直观。 在开发模式下,让应用创建您需要的订阅。将数据库部署到生产环境。 在生产环境中测试您的应用程序,您会看到它现在可以创建您所做的订阅。 希望有用
关于swift - CK订阅和生产容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35896873/