Kinvey iOS query all users

603 Views Asked by At

From Kinvey documentation this is the method to use for querying users:

To query the user collection we recommend instead using +[KCSUserDiscovery lookupUsersForFieldsAndValues:completionBlock:progressBlock:]. This method allows you to supply a dictionary of exact matches for special fields.

Fields for lookup:

  • KCSUserAttributeUsername
  • KCSUserAttributeSurname
  • KCSUserAttributeGivenname
  • KCSUserAttributeEmail
  • KCSUserAttributeFacebookId
 [KCSUserDiscovery lookupUsersForFieldsAndValues:@{ KCSUserAttributeSurname : @"Smith"}
                                    completionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {
                                        if (errorOrNil == nil) {
                                            //array of matching KCSUser objects
                                            NSLog(@"Found %d Smiths", objectsOrNil.count);
                                        } else {
                                            NSLog(@"Got An error: %@", errorOrNil);
                                        }
                                    }
                                      progressBlock:nil];

But if I send empty dictionary, I get an error. So what to put in dictionary to get all the users?

Thank you guys, happy holidays

1

There are 1 best solutions below

0
On BEST ANSWER

To get all the users, you can use the regular app data querying API.

For example,

KCSAppdataStore* store = [KCSAppdataStore storeWithCollection:[KCSCollection userCollection] options:nil];
[store queryWithQuery:[KCSQuery query] withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {
    //handle completion
} withProgressBlock:nil];

This will get a list of all the users the active user has permission to access.