2016-03-09 20 views
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.

我該如何解決這個問題?

回答

1

我有完全相同的問題,解決方案很簡單,但不是很直觀。 在開發模式下,讓應用程序創建您需要的訂閱。將數據庫部署到生產。 在生產環境中測試您的應用程序,您會看到它現在可以創建您所做的訂閱。 希望它有效