从CKRecord
下载CloudKit
,在绘制创作者recordName
时,我可以看到:
(lldb) po record.creatorUserRecordID.recordName
__defaultOwner__
但是,仪表板显示了真正的价值。
为什么不同?!
我希望我不必因为这个首先登录用户而下载?!
答案 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);
}];
}
}
}];
}