使用CloudKit获取用户记录ID失败

Tom*_*ton 3 macos cloudkit

我正在尝试使用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);
    }
}];
Run Code Online (Sandbox Code Playgroud)

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

(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)>";
}
Run Code Online (Sandbox Code Playgroud)

"未经过身份验证"的位似乎不正确 - 我已登录到iCloud帐户,其他iCloud应用程序(例如TextEdit,Reminders)正常工作(无论如何,如果不是,我不应该这样做CKAccountStatusAvailable).还有什么可以/我应该在这里做什么?

这是在OSX,Yosemite beta 3.更新:在beta 4中保持不变.

Tom*_*ton 5

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

遗憾的是,错误消息没有帮助,我很惊讶[CKContainer defaultContainer]没有返回nil,但无论如何代码现在都能正常工作.