creatorUserRecordID.recordName contains “__defaultOwner__” instead of UUID shown in Dashboard

馋奶兔 提交于 2019-12-07 05:09:46

问题


Downloading a CKRecord from CloudKit and when plotting creator recordName, I can see this:

(lldb) po record.creatorUserRecordID.recordName
__defaultOwner__

but, Dashboard show a real value.

Why the difference?!

I hope I do not have to download only because of this the logged in user first?!


回答1:


"__defaultOwner__" mean's its owned by the currently logged in iCloud account. So you could replace that with "Me" or the person's name if you have it. If you want to find out the logged in user's recordID you can use the asynchronous method fetchUserRecordIDWithCompletionHandler.




回答2:


it is a bug

edit this:

- (void)postMoodFeed:(NSString *)moodFeed
{
    CKRecord *moodRecord = [[CKRecord alloc] initWitenter code herehRecordType:@"Mood"];
    moodRecord[@"moodFeed"] = moodFeed`enter code here`

    [[[CKContainer defaultContainer] publicCloudDatabase] saveRecord:moodRecord completionHandler:^(CKRecord *record, NSError *error) {
        [self queryMyMood];
    }];
}

- (void)queryMyMood
{
    // currentUserRecordID is fetched from fetchUserRecordIDWithCompletionHandler: of CKContainer
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"creatorUserRecordID = %@", currentUserRecordID];

    CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Mood" predicate:predicate];

    [[[CKContainer defaultContainer] publicCloudDatabase] performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
        if (results) {
            for (CKRecord *eachRecord in results) {
                // Following logs are all __defaultOwner__
                NSLog(@"%@", eachRecord.creatorUserRecordID.recordName);
                [[[CKContainer defaultContainer] publicCloudDatabase]fetchRecordWithID:eachRecord.creatorUserRecordID completionHandler:^(CKRecord *record, NSError *error) {
                    // All following logs are "Unknown item" error
                    NSLog(@"%@", error);
                }];
            }
        }
    }];
}


来源:https://stackoverflow.com/questions/30502271/creatoruserrecordid-recordname-contains-defaultowner-instead-of-uuid-shown

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