【问题标题】:Fetching user record ID with CloudKit fails使用 CloudKit 获取用户记录 ID 失败
【发布时间】:2014-07-18 21:46:22
【问题描述】:

我正在尝试使用 CloudKit 查找用户记录 ID。我已验证帐户状态为CKAccountStatusAvailable。然后我试试这个:

[[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
    if (error == nil) {
        NSLog(@"Got user record ID (no permission req): %@", recordID);
    } else {
        NSLog(@"Couldn't get user record ID, error=%@", error);
    }
}];

这不可避免地会失败,结果如下:

(lldb) po error
<CKError 0x608000043990: "Not Authenticated" (9/1004); "Account couldn't get container scoped user id, no underlying error received">
(lldb) po [error userInfo]
{
    NSDebugDescription = "CKInternalErrorDomain: 1004";
    NSLocalizedDescription = "Account couldn't get container scoped user id, no underlying error received";
    NSUnderlyingError = "<CKError 0x608000044080: \"Unknown Error\" (1004)>";
}

“未验证”位似乎不正确——我已登录 iCloud 帐户,其他 iCloud 应用程序(例如 TextEdit、Reminders)正常工作(无论如何,如果我没有,我不应该是得到CKAccountStatusAvailable)。我还能/应该在这里做什么?

这是在 OSX,优胜美地 beta 3 上。更新:在 beta 4 中保持不变。

【问题讨论】:

    标签: macos cloudkit


    【解决方案1】:

    问题在于默认与自定义 CloudKit 容器的混淆。我已将我的应用程序配置为使用自定义容器,但试图在我的代码中使用默认容器(在设置功能时我可能有点困惑)。无论如何,关键是从应用程序的功能中获取容器名称,然后在运行时使用[CKContainer containerWithIdentifier:] 而不是使用[CKContainer defaultContainer] 来查找它。

    不幸的是,错误消息没有帮助,我很惊讶[CKContainer defaultContainer] 没有返回 nil,但无论如何代码现在可以工作了。

    【讨论】:

    • 在 Swift 中:let container = CKContainer(identifier: "your container name")
    【解决方案2】:

    遇到同样的问题,意识到我在模拟器上使用 iCloud 登录了我的开发者帐户,然后切换到我的另一个并开始工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2017-07-11
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      相关资源
      最近更新 更多