# Presence (/en/realtime-media/im/build/build-core-messaging/presence/ios)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

The presence feature enables users to publicly display their online presence status and quickly determine the status of other users. Users can also customize their presence status, which adds fun and diversity to real-time chatting.

    The following illustration shows the implementation of creating a custom presence status and how various presence statues look in a contact list:

    ![1655302046418](https://web-cdn.agora.io/docs-files/1655302046418)

    ## Understand the tech [#understand-the-tech-1]

    The Chat SDK provides the `IAgoraChatPresenceManager`, `AgoraChatPresence`, and `AgoraChatPresenceManagerDelegate` classes for presence management, which allows you to implement the following features:

    The following figure shows the workflow of how clients subscribe to and publish presence statuses:

    Presence workflow

    ![1655307187099](https://web-cdn.agora.io/docs-files/1655307187099)

    ## Prerequisites [#prerequisites-1]

    Before proceeding, ensure that your environment meets the following requirements:

    * You have initialized the Chat SDK. For details, see [SDK quickstart](../../get-started-sdk).
    * You understand the API call frequency limit as described in [Limitations](../limitations).
    * You have activated the presence feature in [Agora Console](https://console.agora.io/v2).

    ## Implementation [#implementation-1]

    This section introduces how to implement presence functionalities in your project.

    ### Subscribe to the presence status of one or more users [#subscribe-to-the-presence-status-of-one-or-more-users-1]

    By default, you do not subscribe to any users. To subscribe to the presence statuses of the specified users, you can call `subscribe`.

    Once the subscription succeeds, the `completion` callback is triggered, notifying you about the current statuses of the specified users synchronously. Whenever the specified users update their presence statuses, the `presenceStatusDidChanged` callback is triggered, notifying you about the updated statuses asynchronously.

    The following code sample shows how to subscribe to the presence status of one or more users:

    ```objc
    [[[AgoraChatClient sharedClient] presenceManager] subscribe:@[@"Alice",@"Bob"] expiry:7*24*3600 completion:^(NSArray *presences, AgoraChatError *error) {
    }];
    ```

    <CalloutContainer type="info">
      <CalloutDescription>
        You can subscribe to a maximum of 100 users at each call. The total subscriptions of each user cannot exceed 3,000. Once the number of subscriptions exceed the limit, the subsequent subscriptions with longer durations succeed and replace the existing subscriptions with shorter durations.The subscription duration can be a maximum of 30 days. When the subscription to a user expires, you need to subscribe to this user once again. If you subscribe to a user again before the current subscription expires, the duration is reset.
      </CalloutDescription>
    </CalloutContainer>

    ### Publish a custom presence status [#publish-a-custom-presence-status-1]

    You can call `publishPresenceWithDescription` to publish a custom status. Whenever your presence status updates, the users who subscribe to you receive the `presenceStatusDidChanged` callback.

    The following code sample shows how to publish a custom status:

    ```objc
    [[[AgoraChatClient sharedClient] presenceManager] publishPresenceWithDescription:@"custom presence" completion:^(AgoraChatError *error) {
    }];
    ```

    ### Listen for presence status updates [#listen-for-presence-status-updates-1]

    Refer to the following code sample to listen for presence status updates:

    ```objc
    // Adds the presence status listener.
    [[[AgoraChatClient sharedClient] presenceManager] addDelegate:self delegateQueue:nil];

    // Occurs when the presence statuses of the subscriptions update.
    - (void) presenceStatusDidChanged:(NSArray*)presences
    {
        NSLog(@"presenceStatusDidChanged:%@",presences);
    }
    ```

    ### Unsubscribe from the presence status of one or more users [#unsubscribe-from-the-presence-status-of-one-or-more-users-1]

    You can call `unsubscribe` to unsubscribe from the presence statuses of the specified users, as shown in the following code sample:

    ```objc
    [[[AgoraChatClient sharedClient] presenceManager] unsubscribe:@[@"Alice"] completion:^(AgoraChatError *error) {

    }];
    ```

    ### Retrieve the list of subscriptions [#retrieve-the-list-of-subscriptions-1]

    You can call `fetchSubscribedMembersWithPageNum` to retrieve the list of your subscriptions in a paginated list, as shown in the following code sample:

    ```objc
    [[[AgoraChatClient sharedClient] presenceManager] fetchSubscribedMembersWithPageNum:0 pageSize:50 Completion:^(NSArray* members,AgoraChatError*error){
    }];
    ```

    ### Retrieve the presence status of one or more users [#retrieve-the-presence-status-of-one-or-more-users-1]

    You can call `fetchPresenceStatus` to retrieve the current presence statuses of the specified users without the need to subscribe to them, as shown in the following code sample:

    ```objc
    // You can pass in up to 100 user IDs whose presence status you retrieve.
    [[[AgoraChatClient sharedClient] presenceManager] fetchPresenceStatus:@[@"Alice",@"Tom"] completion:^(NSArray* presences,AgoraChatError*error){
    }];
    ```

    
  
      
  
      
  
      
  
      
  
      
  
