CKSubscriptions 和生产容器

3 icloud swift

嗨,我正在尝试创建一个 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)
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是此代码仅适用于模拟器,当我在真实设备上运行该应用程序时,出现此错误:

尝试在生产容器中创建订阅。

我怎样才能解决这个问题?

use*_*737 6

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