问题描述
我正在尝试使用CloudKit查找用户记录ID。我已验证帐户状态为 CKAccountStatusAvailable
。然后我尝试一下:
I'm trying to find the user record ID with CloudKit. I've verified that the account status is CKAccountStatusAvailable
. Then I try this:
[[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);
}
}];
这不可避免地失败,结果如下:
This inevitably fails with the following result:
(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
)。我还能在这里做什么?
The "not authenticated" bit seems to be incorrect-- I'm logged in to an iCloud account and other iCloud apps (e.g. TextEdit, Reminders) work normally (and anyway if I weren't, I shouldn't be getting CKAccountStatusAvailable
). What else can/should I be doing here?
这是在OSX上的优胜美地beta3。更新:在beta 4中保持不变。
This is on OSX, Yosemite beta 3. Update: unchanged in beta 4.
推荐答案
问题是默认与自定义CloudKit容器的混淆。我已经将我的应用程序配置为使用自定义容器,但是试图在代码中使用默认容器(设置功能时,我可能有些困惑)。无论如何,关键是要从应用程序的功能中获取容器名称,然后在运行时使用 [CKContainer containerWithIdentifier:]
而不是使用 [ CKContainer defaultContainer]
。
The problem was confusion of default vs. custom CloudKit containers. I had configured my app to use a custom container, but was attempting to use the default container in my code (I was probably a little confused when setting up the capabilities). Anyway the key was to get the container name from the app's capabilities and then look it up at run time using [CKContainer containerWithIdentifier:]
instead of using [CKContainer defaultContainer]
.
不幸的是,该错误消息没有帮助,令我感到惊讶的是, [CKContainer defaultContainer]
没有返回nil,但是无论如何该代码现在都能正常工作。
The error message was unfortunately not helpful, and I'm surprised that [CKContainer defaultContainer]
did not return nil, but in any case the code works now.
这篇关于使用CloudKit提取用户记录ID失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!