【问题标题】:Saving Record in CloudKit not working [Swift 3]在 CloudKit 中保存记录不起作用 [Swift 3]
【发布时间】:2016-12-14 05:14:00
【问题描述】:

我正在尝试保存我在 CloudKit 仪表板中创建的记录。

@IBAction func signUpPressed(_ sender: AnyObject) {

    let authInfo = AuthInfo()

    authInfo.email = emailField.text!
    authInfo.firstName = firstField.text!
    authInfo.lastName = lastField.text!
    authInfo.username = usernameField.text!
    authInfo.password = passwordField.text!

    let container = CKContainer.default()
    let privateData = container.privateCloudDatabase

    let record = CKRecord(recordType: "Authentication")
    record.setValue(authInfo.email, forKey: "email")
    record.setValue(authInfo.username, forKey: "username")
    record.setValue(authInfo.firstName, forKey: "firstName")
    record.setValue(authInfo.lastName, forKey: "lastName")
    record.setValue(authInfo.password, forKey: "password")
    privateData.save(record, completionHandler: { record, error in
        if error != nil {
            print(error)

        } else {

        }

而且,我很确定我的代码没问题。 (CloudKit 框架肯定已正确导入,并且 CloudKit 已使用有效的开发人员帐户和容器正确启用,没有问题)但是当我尝试运行此代码时,我收到一条错误消息,说我有一个授权帐户。但是,通过确保您在模拟器上登录到 iCloud(我使用的是 Xcode 8)似乎已经解决了其他类似的问题,但是我已经检查并再次检查了我是否登录到了 iCloud,所以我没有知道问题是什么。我该如何解决这个问题。它实际上与我的代码有关吗?

【问题讨论】:

  • 你能显示实际的错误信息吗?
  • @grimfrog 这里是

标签: ios-simulator cloudkit swift3 xcode8 ckrecord


【解决方案1】:

您的代码看起来不错。它与身份验证有关。

您使用的是新的 iCloud 测试帐户还是您的开发者帐户?如果是全新帐户,我会先尝试通过 iCloud.com 登录浏览器。

另一种选择是重置模拟器 (Reset Content and Settings) 并在 Settings > iCloud 中重新设置 iCloud。

【讨论】:

    猜你喜欢
    • 2014-08-27
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    相关资源
    最近更新 更多