gpt4 book ai didi

ios - 如何在 CloudKit 中设置对当前用户的引用?

转载 作者:行者123 更新时间:2023-11-29 12:11:53 25 4
gpt4 key购买 nike

我有一个 CKRecordType,其中有一个引用字段,我想将其设置为应用程序的当前用户。 enter image description here

CKRecord * record = [[CKRecord alloc] initWithRecordType:@"UserStatus"];
[record setValue:@"online" forKey:@"status"];
// what user should be?
[record setValue:user forKey:@"user"];

我应该怎么做?

最佳答案

首先,获取userId:

- (void)getUserId
{
[self.defaultContainer fetchUserRecordIDWithCompletionHandler:^(CKRecordID * _Nullable recordID,
NSError * _Nullable error)
{
if (error == nil)
{
self.userRecordID = recordID;
}
}];
}

然后:

CKRecord * record = [[CKRecord alloc] initWithRecordType:@"UserStatus"];
record[@"status"] = @"online";

CKReference *userReference = [[CKReference alloc] initWithRecordID:self.userRecordID action:CKReferenceActionDeleteSelf];
record[@"user"] = userReference;

关于ios - 如何在 CloudKit 中设置对当前用户的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33224578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com