> ## 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.

# User Presence

> Learn how to track user presence updates and check user status using ping.

## 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.

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

## Subscribe to contact presence updates

You can track the contact presence updates in real-time using the `chatDidReceiveContactItemActivity(_ userID:isOnline:status:)` method of the `QBChatDelegate`. However, you can track the presence updates of only those users who have been added to the contact list. See [this section](/sdks/ios-chat-contact-list) to learn how to implement the Contact List.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: - Life Cycle
    override func viewDidLoad() {
        super.viewDidLoad()

        QBChat.instance.addDelegate(self)
    }

    //MARK: QBChatDelegate
    func chatDidReceiveContactItemActivity(_ userID: UInt, isOnline: Bool, status: String?) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: - Life Cycle
    - (void)viewDidLoad {
        [super viewDidLoad];

        [QBChat.instance addDelegate:self];
    }

    //MARK: QBChatDelegate
    - (void)chatDidReceiveContactItemActivity:(NSUInteger)userID isOnline:(BOOL)isOnline status:(NSString *)status {

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

## Ping user

QuickBlox SDK can send application-level pings to a user. As a result, you can check if the user is connected to the Chat server.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    let userId = 221809
    let timeout = 20.0
    QBChat.instance.pingUser(withID: userId, timeout: timeout) { (timeInterval, success) in
        // time interval of ping and whether it was successful
    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    NSUInteger userId = 221809;
    NSTimeInterval timeout = 20.0;
    [QBChat.instance pingUserWithID:userId timeout:timeout completion:^(NSTimeInterval timeInterval, BOOL success) {
        // time interval of ping and whether it was successful
    }];
    ```
  </Tab>
</Tabs>

SwiftObjective-C

| Argument | Required | Description                                                                                                                                                                                                                      |
| -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| userId   | yes      | ID of the user.                                                                                                                                                                                                                  |
| timeout  | no       | Ping timeout. To control how much time it takes to respond to a ping, you should set a ping timeout. If the response isn't received within the specified time frame, then the error callback is called. Default: **30** seconds. |

As a result, a completion block with `timeInterval` and `success` arguments is called.

| Argument     | Description                                                                                                                                                                          |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| timeInterval | A double parameter. Indicates how long it took to ping in seconds.                                                                                                                   |
| success      | A boolean parameter. Indicates whether the ping was successful. If the sucess=1, the ping is successful (the user is connected to the Chat). If sucess=0, the ping isn't successful. |

## Ping server

QuickBlox SDK can send application-level pings to a server. As a result, you can check if there is a connection with the Chat server.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    let timeout = 20.0
    QBChat.instance.pingServer(withTimeout: timeout) { (timeInterval, success) in
        // time interval of ping and whether it was successful
    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    NSTimeInterval timeout = 20.0;
    [QBChat.instance pingServerWithTimeout:timeout completion:^(NSTimeInterval timeInterval, BOOL success) {
        // time interval of ping and whether it was successful
    }];
    ```
  </Tab>
</Tabs>

| Argument | Required | Description                                                                                                                                                                                                                       |
| -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| timeout  | no       | Ping timeout. To control how much time it takes to respond to a ping, you should set a ping timeout. If the response wasn't received within the specified time frame, then the error callback is called. Default: **30** seconds. |

As a result, a completion block with `timeInterval` and `success` arguments is called.

| Argument     | Description                                                                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| timeInterval | A double parameter. Indicates how long it took to ping in seconds.                                                                                 |
| success      | A boolean parameter. Indicates whether the ping was successful. If the sucess=1, the ping was successful. If sucess=0, the ping wasn't successful. |
