【问题标题】:Cloudkit gives error when trying to save a recordCloudkit 尝试保存记录时出错
【发布时间】:2014-12-28 10:58:39
【问题描述】:

我试图简单地将记录保存到用户私有数据库,但是当我运行 privateDB.saveRecord() 时,我收到一条错误消息

Not Authenticated" (9/1002); "CloudKit access was denied by user settings"; Retry after 3.0 seconds>.

此帐户能够登录到 cloudkit 仪表板,因此它是应用程序的开发人员。还有哪些其他问题可能导致这种情况?任何帮助将不胜感激,我已经坚持了这么久。

这是我的代码:

//variable instantiation
container = CKContainer.defaultContainer()
println(container.containerIdentifier)
publicDB = container.publicCloudDatabase
privateDB = container.privateCloudDatabase

//save record code
let passRecord = CKRecord(recordType: "Password")
passRecord.setValue("testytestPow", forKey: "title")
passRecord.setValue("password02", forKey: "value")
privateDB.saveRecord(passRecord, completionHandler: { (record, error) -> Void in
    if (error != nil) {
        println(error)
    } else {
        NSLog("Saved in cloudkit")
        self.fetchTodos()
    }
})

【问题讨论】:

    标签: macos swift icloud cloudkit icloud-api


    【解决方案1】:

    我在模拟器上遇到了同样的问题,直到我做了这样的事情:

    CKContainer.defaultContainer().accountStatusWithCompletionHandler { (accountStat, error) in
            if (accountStat == .Available) {
                print("iCloud is available")
                for wishlist in wl {
                    let wlRecord = CKRecord(recordType: "WishList")
                    wlRecord.setObject(wishlist.type, forKey: "type")
                    wlRecord.setObject(wishlist.term_id, forKey: "term_id")
    
                    publicDB.saveRecord(wlRecord) {
                        record, error in
                        if error != nil {
                            print(error?.localizedDescription)
                        } else {
                            print(record?.objectForKey("type") as! String + " recorded")
                        }
                    }
                }
            }
            else {
                print("iCloud is not available")
            }
        }
    

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      我在尝试创建自定义 CKRecordZone 并同时保存新的 CKRecord 时收到此错误。我通过将 CKRecord 保存在 CKModifyRecordZone 方法的完成块中解决了这个问题。

      【讨论】:

        【解决方案3】:

        对我来说 我以相同的方法调用“保存新数据”、“检索数据”和“更新检索数据”。 删除“保存新数据”后一切正常。

        【讨论】:

          【解决方案4】:

          发生了同样的事情,因为我试图从 MutableArray 添加许多记录。为了解决这个问题,我不得不对 saveRecord 进行递归调用。

          MyObject *obj = [arrayOfObjects ObjectAtIndex:index];
          [self addRecord];
          

          然后在addRecord方法中

          - (void) addRecord {
              // if all objects added, exit recursive method
              if(index == [arrayOfObjects count]) {
                  return;
              }
          
              MyObject *obj = [arrayOfObjects ObjectAtIndex:index];
          
              [publicDatabase saveRecord:rec completionHander:^(CKRecord *myRec, NSError *error) {
              if (!error) {
                  index++
                  [self addRecord];
          
              }
          }
          

          【讨论】:

            【解决方案5】:

            我在尝试一次将记录列表全部上传到数据库时遇到此错误。当我一次做一个(在上传下一个之前等待回复)时,问题就消失了。

            【讨论】:

              【解决方案6】:

              我发现在升级到 iCloud 驱动器之前我根本无法连接到 CloudKit;就我而言,我能够在模拟器中做到这一点。如果您设置了 2 因素身份验证,您似乎也无法在模拟器上登录 iCloud。

              【讨论】:

              • 我不能投票,因为我没有足够的积分 :( 但是非常感谢你解决了这个问题......我不明白为什么这会是问题,但谢谢你很多!
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-08-27
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-11-30
              • 1970-01-01
              相关资源
              最近更新 更多