Ios 如何在CloudKit中设置对当前用户的引用?
我有一个Ios 如何在CloudKit中设置对当前用户的引用?,ios,cloudkit,Ios,Cloudkit,我有一个CKRecordType,其中有一个参考字段,我想设置为应用程序的当前用户。 我应该怎么做?首先,获取用户ID: - (void)getUserId { [self.defaultContainer fetchUserRecordIDWithCompletionHandler:^(CKRecordID * _Nullable recordID,
CKRecordType
,其中有一个参考字段,我想设置为应用程序的当前用户。
我应该怎么做?首先,获取
用户ID
:
- (void)getUserId
{
[self.defaultContainer fetchUserRecordIDWithCompletionHandler:^(CKRecordID * _Nullable recordID,
NSError * _Nullable error)
{
if (error == nil)
{
self.userRecordID = recordID;
}
}];
}
然后:
- (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;