Getting a Member List of a Group

A group owner and members can get a list of members of the group with the getMemberList(_:) method. This method will return a list of KiiUser instances representing group members.

Note that the KiiUser instance returned by the method only contains the ID. Execute the refreshSynchronous() method to get the user's latest information from Kii Cloud.

If the returned user is different from the logged-in user, available user information is limited. For more information, see User Attributes.

Here's an example:

Swift:

  • // Get a list of members of the group.
    guard let members = try? group.getMemberListSynchronous() as! [KiiUser] else{
      // Handle the error.
      return
    }
    
    for user in members{
      do{
        // Refresh the member to retrieve the latest data from Kii Cloud.
        try user.refreshSynchronous()
      } catch let error as NSError {
        // Handle the error.
        return
      }
    
      // Do something.
    }
  • // Get a list of members of the group.
    group.getMemberList { (group, members, error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Create a dispatch queue to which blocks can be submitted.
      let serialQueue = DispatchQueue(label: "com.kii.serial", attributes: [])
    
      for obj in members! {
        let user = obj as! KiiUser
    
        // Submit a block for asynchronous execution on the dispatch queue.
        serialQueue.async(execute: {
          do{
            // Refresh the member to retrieve the latest data from Kii Cloud.
            try user.refreshSynchronous()
          } catch let error as NSError {
            // Handle the error.
            return
          }
    
          // Do something.
        })
      }
    }

Objective-C:

  • NSError *error;
    
    // Get a list of members of the group.
    NSArray *members = [group getMemberListSynchronous:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
    
    for (KiiUser *user in members) {
      // Refresh the member to retrieve the latest data from Kii Cloud.
      [user refreshSynchronous:&error];
    
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      // Do something.
    }
  • // Get a list of members of the group.
    [group getMemberListWithBlock:^(KiiGroup *group, NSArray *members, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      // Create a dispatch queue to which blocks can be submitted.
      dispatch_queue_t serialQueue = dispatch_queue_create("com.kii.serial", DISPATCH_QUEUE_SERIAL);
    
      for (KiiUser *user in members) {
        // Submit a block for asynchronous execution on the dispatch queue.
        dispatch_async(serialQueue, ^{
          // Refresh the member to retrieve the latest data from Kii Cloud.
          [user refreshSynchronous:&error];
    
          if (error != nil) {
            // Handle the error.
            return;
          }
    
          // Do something.
        });
      }
    }];