4

我正在尝试使用 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 中保持不变。

4

2 回答 2

5

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

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

于 2014-07-22T23:26:43.200 回答
1

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

于 2015-07-14T09:30:26.003 回答