1
您好我想創建一個CKSubscription,我用這個代碼:CKSubscriptions和生產容器
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.
我該如何解決這個問題?