Fetching user record ID with CloudKit fails

落花浮王杯 提交于 2019-12-23 17:18:07

问题


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)>";
}

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?

This is on OSX, Yosemite beta 3. Update: unchanged in beta 4.


回答1:


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].

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.




回答2:


Had same problem, realised I was logged in with my developer account on the simulator with iCloud, switched to my other one and worked then.



来源:https://stackoverflow.com/questions/24834265/fetching-user-record-id-with-cloudkit-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!