creatorUserRecordID.recordName包含“__defaultOwner__”而不是仪表板中显示的UUID

时间:2015-05-28 09:18:34

标签: ios cloudkit ckrecord

CKRecord下载CloudKit,在绘制创作者recordName时,我可以看到:

(lldb) po record.creatorUserRecordID.recordName
__defaultOwner__

但是,仪表板显示了真正的价值。

enter image description here

为什么不同?!

我希望我不必因为这个首先登录用户而下载?!

2 个答案:

答案 0 :(得分:4)

" __ defaultOwner __"意味着它由当前登录的iCloud帐户拥有。所以你可以用" Me"或者你的名字。如果要查找登录用户的recordID,可以使用异步方法fetchUserRecordIDWithCompletionHandler。

答案 1 :(得分:-1)

这是一个错误

编辑:

- (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);
                }];
            }
        }
    }];
}