> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Contact List

> Learn how to create, update, manage, and add users to your contact list.

The Contact List API is rather straightforward. A user A sends a request to become "friends" with a user B. The user B accepts the friend request. And now the user A and B appear in each other roster.

Visit [Key Concepts](/docs/key-concepts) page to learn the most important QuickBlox concepts.

## Before you begin

1. Register a [QuickBlox account](https://admin.quickblox.com/signin). This is a matter of a few minutes and you will be able to use this account to build your apps.
2. Configure QuickBlox SDK for your app. Check out [Setup](/sdks/ios-setup) page for more details.
3. Create a user session to be able to use QuickBlox functionality. See [Authentication](/sdks/ios-authentication) page to learn how to do it.
4. Connect to the Chat server. See [Connection](/sdks/ios-chat-connection) page to learn how to do it.

## Access contact list

The following function gives you access to all contact list items.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    // array of accepted contacts
    let contacts = QBChat.instance.contactList?.contacts

    // array of pending requests
    let pendingRequests = QBChat.instance.contactList?.pendingApproval
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    // array of accepted contacts
    NSArray *contacts = QBChat.instance.contactList.contacts;

    // array of pending requests
    NSArray *pendingApproval = QBChat.instance.contactList.pendingApproval;
    ```
  </Tab>
</Tabs>

## Add user to your contact list

To add a user to the contact list, use the following snippet.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    let userID: UInt = 34
    QBChat.instance.addUser(toContactListRequest: userID) { (error) in

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    NSUInteger userID = 34;
    [QBChat.instance addUserToContactListRequest:userID completion:^(NSError * _Nullable error) {

    }];
    ```
  </Tab>
</Tabs>

<Note>
  Maximum number of contacts is 300.
</Note>

The `QBChat` instance will call its delegate’s `chatDidReceiveContactAddRequest(fromUser:)` method and the user will receive the request to be added to the contact list.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidReceiveContactAddRequest(fromUser userID: UInt) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}

    //MARK: QBChatDelegate
    - (void)chatDidReceiveContactAddRequestFromUser:(NSUInteger)userID {

    }
    ```
  </Tab>
</Tabs>

## Confirm the contact request

To confirm the request, use `confirmAddContactRequest()` method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    [QBChat.instance confirmAddContactRequest:userID completion:^(NSError * _Nullable error) {

    }];
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance confirmAddContactRequest:userID completion:^(NSError * _Nullable error) {

    }];
    ```
  </Tab>
</Tabs>

The `QBChat` instance will call `chatDidReceiveAcceptContactRequest(fromUser:)` delegate method and this user will be informed that you have accepted the contact request.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidReceiveAcceptContactRequest(fromUser userID: UInt) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidReceiveAcceptContactRequestFromUser:(NSUInteger)userID {

    }
    ```
  </Tab>
</Tabs>

## Reject the contact request

To reject the request, use the `rejectAddContactRequest()` method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    QBChat.instance.rejectAddContactRequest(userID) { (error) in

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance rejectAddContactRequest:userID completion:^(NSError * _Nullable error) {

    }];
    ```
  </Tab>
</Tabs>

The `QBChat` instance will call its `chatDidReceiveRejectContactRequest(fromUser:)` delegate method and this user will be informed that you have declined the contact request.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidReceiveRejectContactRequest(fromUser userID: UInt) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidReceiveRejectContactRequestFromUser:(NSUInteger)userID {

    }
    ```
  </Tab>
</Tabs>

## Remove user from the contact list

To remove a previously added user from the contact list, use the following method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    QBChat.instance.removeUser(fromContactList: 34) { (error) in

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance removeUserFromContactList:34 completion:^(NSError * _Nullable error) {

    }];
    ```
  </Tab>
</Tabs>

## Contact list updates

You can also track contact list updates in a real time by using delegates.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatContactListDidChange(_ contactList: ContactList) {

    }

    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatContactListDidChange:(QBContactList *)contactList {

    }
    ```
  </Tab>
</Tabs>
