2017-02-23 157 views
0

我必须在这里写什么?无法让Graph + iCloud工作

db = Graph(cloud: "iCloud.com.devname.appname", completion: { (done, error) in 
      if let errore = error { 
       debugPrint("Error iCloud: \(errore.localizedDescription)") 
       return 
      } 
     }) 

db = Graph(cloud: "fantasyString", completion: { (done, error) in 
      if let errore = error { 
       debugPrint("Errore iCloud: \(errore.localizedDescription)") 
       return 
      } 
     }) 

我什么都试过,但我无法做出iCloud的工作

感谢你的帮助,丹尼尔

编辑: 的方式,我读数据表格db:

var customers : [Entity] { 
     let search = Search<Entity>(graph: db).for(types: "Customers") 
     return search.sync(completion: nil).sorted { ($0["name"] as! String) < ($1["name"] as! String)} 
    } 

我保存记录的方式:

func newCustomer(name:String, phone:String, mail:String, closure: @escaping()->()) { 

     let cliente = Entity(type: "Customers") 
     cliente["name"] = name 
     cliente["phone"] = phone 
     cliente["mail"] = mail 
     db.sync { (done, error) in 
      if let errore = error { 
       debugPrint("Errore addCustomer: \(errore.localizedDescription)") 
       return 
      } 
      if done { closure() } 
     } 
    } 

EDIT 2:GraphDelegate实现:

extension DataManager: GraphDelegate { 

    func graphWillPrepareCloudStorage(graph: Graph, transition: GraphCloudStorageTransition) { 
     debugPrint("graphWillPrepareCloudStorage") 
     if transition == .initialImportCompleted { 
      debugPrint("iCloud initialImportCompleted ok") 
      self.clientiCont?.tableView.reloadData() 
     } 
    } 

    func graphDidPrepareCloudStorage(graph: Graph) { 
     debugPrint("graphDidPrepareCloudStorage") 
     self.clientiCont?.tableView.reloadData() 
    } 

    func graphWillUpdateFromCloudStorage(graph: Graph) { 
     debugPrint("graphWillUpdateFromCloudStorage") 
     self.clientiCont?.tableView.reloadData() 
    } 

    func graphDidUpdateFromCloudStorage(graph: Graph) { 
     debugPrint("graphDidUpdateFromCloudStorage") 
     // refresh clienti 
     self.clientiCont?.tableView.reloadData() 

     // refresh lista ordini 
     self.gestCliCont?.tableOrder.reloadData() 

     // refresh oridine 
     self.gestOrdCont?.showOrder() 
     self.gestOrdCont?.tableProdotti.reloadData() 
    } 


} 

编辑:iCloud的配置 enter image description here

+0

嘿,你有没有设置你的iCloud容器与苹果,并启用它在你的应用程序? – CosmicMind

+0

当然......我必须在云字符串中写什么?捆绑标识符或幻想字符串? – Enlil

+0

我把标识符的最后部分。例如,如果标识符是“com.cosmicmind.Focus”,我把'Focus'。另外,请确保您已在iCloud的功能面板中选择了“iCloud Documents”。 – CosmicMind

回答

0

感谢我的一个学生,我发现bug:

  • 如果你打一个rec ORD这一切办法正常工作: let record = Entity(type: "Names", graph: self.db)
  • ,但如果你使用这个初始化它并不:let record = Entity(type: "Names")

所以解决方法是:做好记录这样 let record = Entity(type: "Names", graph: self.db)