[英]How to set the reference to the current user, in CloudKit?
I have a CKRecordType
with a reference field that I want to set to the current user of the app. 我有一个
CKRecordType
其中包含我想设置为应用程序当前用户的参考字段。
CKRecord * record = [[CKRecord alloc] initWithRecordType:@"UserStatus"];
[record setValue:@"online" forKey:@"status"];
// what user should be?
[record setValue:user forKey:@"user"];
How should I do that? 我应该怎么做?
First, get the userId
: 首先,获取
userId
:
- (void)getUserId
{
[self.defaultContainer fetchUserRecordIDWithCompletionHandler:^(CKRecordID * _Nullable recordID,
NSError * _Nullable error)
{
if (error == nil)
{
self.userRecordID = recordID;
}
}];
}
Then: 然后:
CKRecord * record = [[CKRecord alloc] initWithRecordType:@"UserStatus"];
record[@"status"] = @"online";
CKReference *userReference = [[CKReference alloc] initWithRecordID:self.userRecordID action:CKReferenceActionDeleteSelf];
record[@"user"] = userReference;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.