CloudKit 获取所有用户记录

CloudKit Fetch all User records

我想获取在我的应用程序的同一个 public 默认容器中工作的所有用户。 是否可以获取所有用户 ID?

当我尝试这样做时:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"]; // to search for all the records
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Users" predicate:predicate];
[_publicDB performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
    if (error) {
        // Error handling for failed fetch from public database
        NSLog(@"Error:%@", error);
    }
    else {
        // Display the fetched records
        NSLog(@"Users: %@", results);
    }
}];

我收到这样的错误:

Error:<CKError 0x7f9c6b7331f0: "Permission Failure" (10/2007); server message = "Can't query system types"; uuid = 9CBA8EB0-D9DC-46B2-BDF4-10C036599642; container ID = "iCloud.com.xxx.xxx.MyApp">

你知道我怎样才能做到这一点吗?我想从客户的角度 (iOS) 了解使用我的应用程序的其他用户有哪些。

Users recordType是一个特殊的recordType,您无法查询。如果要执行此类查询,则应创建自己的 recordType 并为每个用户插入一条记录。