---
schema_version: "1"
id: 952db0823a91a64aa6aafc956edc00b34c3e8139c07a583940d917f139c6c3e1
title: Notifications for Chat Activity
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/service-sdk-ios/guides/live-agent-notifications.md
canonical_url: https://developer.salesforce.com/docs/service/service-sdk-ios/guide/live-agent-notifications.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a7d4880eb11166297407e72a5b5179239e53e6d84ce90840fe90002df2f8edc0
products:
  - Embedded Service Chat SDK for iOS Developer Guide
  - Service Cloud Developer Content
---

# Notifications for Chat Activity

If there's chat activity when the user is not viewing the chat session, you can present that information to them using the iOS notification system.

**important:** The legacy chat product is scheduled for retirement on February 14, 2026, and is in maintenance mode until then. During this phase, you can continue to use chat, but we no longer recommend that you implement new chat channels. To avoid service interruptions to your customers, migrate to [Messaging for In-App and Web](https://help.salesforce.com/s/articleView?id=service.miaw_intro_landing.htm&type=5) before that date. Messaging offers many of the [chat features](https://help.salesforce.com/s/articleView?id=service.miaw_chat_vs_messaging.htm&type=5) that you love plus asynchronous conversations that can be picked back up at any time. Learn about chat retirement in [Help](https://help.salesforce.com/s/articleView?id=001790618&type=1).

Notifications can be sent to the user when the user isn't viewing the chat session. A notification can appear when the app is in the background, or when the app is in the foreground but the chat session is minimized. The following activities can cause notifications:

- Agent has connected
- Agent sent a message
- Agent requested a file transfer
- Agent canceled a file transfer
- Agent ended a session
- Session will timeout soon

To ensure that the app can send these notifications while in the background, chat must be configured to allow background execution (`allowBackgroundExecution`) and to allow for background notifications (`allowBackgroundNotifications`). Both these settings are turned on by default. See [Configure a Chat Session](https://developer.salesforce.com/docs/service/service-sdk-ios/guide/configure-lac-session.md) for details.

1.  Import the `UserNotifications` framework in your `AppDelegate` class.

    In Swift:

    ```java
    import UserNotifications
    ```

    In Objective-C:

    ```java
    @import UserNotifications;
    ```

2.  Register for local notifications in your `AppDelegate`'s `didFinishLaunchingWithOptions` method.

    In Swift:

    ```java
    // Get the notification center object
    let center = UNUserNotificationCenter.current()

    // Register a delegate (see next step for delegate implementation)
    center.delegate = self

    // Request authorization
    center.requestAuthorization(options: [.alert,.sound],
                                completionHandler: { granted, error in
      // Enable or disable features based on authorization
    })

    // Create general category
    let generalCategory = UNNotificationCategory(identifier: "General", actions: [],
    intentIdentifiers: [], options: .customDismissAction)
    let categorySet: Set<UNNotificationCategory> = [generalCategory]

    // Set category
    center.setNotificationCategories(categorySet)
    ```

    In Objective-C:

    ```java
    // Get the notification center object
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];

    // Register a delegate (see next step for delegate implementation)
    [center setDelegate:self];

    // Request authorization
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
            completionHandler:^(BOOL granted, NSError * _Nullable error) {
      // Enable or disable features based on authorization
    }];

    // Create general category
    UNNotificationCategory* generalCategory =
      [UNNotificationCategory
        categoryWithIdentifier:@"GENERAL"
                       actions:@[]
             intentIdentifiers:@[]
                       options:UNNotificationCategoryOptionCustomDismissAction];

    // Set category
    [center setNotificationCategories:[NSSet setWithObjects:generalCategory, nil]];
    ```

3.  Implement `UNUserNotificationCenterDelegate`. Handle the `didReceiveNotificationResponse` and `willPresentNotification` methods.

    iOS calls the `didReceiveNotificationResponse` method when your app is in the background. In this method, you can tell your app to enter the foreground and for chat to maximize. To perform this behavior, use the [`handle(notification:)`](https://developer.salesforce.com/docs/service/service-sdk-ios/guide/%3Chttps://forcedotcom.github.io/ServiceSDK-iOS/releases/api/234.1/Classes/SCSChatInterface.html#/c:objc(cs)SCSChatInterface(im)handleNotification:>) method on the [`SCSChatInterface`](https://forcedotcom.github.io/ServiceSDK-iOS/releases/api/234.1/Classes/SCSChatInterface.html) object, which is accessible from the `chatUI` property of the [`ServiceCloud`](https://forcedotcom.github.io/ServiceSDK-iOS/releases/api/234.1/Classes/SCServiceCloud.html) shared instance.

    iOS calls the `willPresentNotification` method when your app is in the foreground. To determine whether to display the notification, use the [`shouldDisplayNotificationInForeground`](https://developer.salesforce.com/docs/service/service-sdk-ios/guide/%3Chttps://forcedotcom.github.io/ServiceSDK-iOS/releases/api/234.1/Classes/SCSChatInterface.html#/c:objc(cs)SCSChatInterface(im)shouldDisplayNotificationInForeground>) method (accessible from the `chatUI` property of the [`ServiceCloud`](https://forcedotcom.github.io/ServiceSDK-iOS/releases/api/234.1/Classes/SCServiceCloud.html) shared instance). If the Chat UI is already showing the relevant information related to this event, the method returns `false`.

    In Swift:

    ```java
    /**
     This delegate method is executed when the application launches as a result
     of the user interacting with a notification when it is in the background.
     The result of passing the notification to Chat is that we will
     maximize if the notification was scheduled as a result of a chat event.
    */
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler:
                                @escaping () -> Void) {

      let chat = ServiceCloud.shared().chatUI!
      chat.handle(response.notification)
    }

    /**
     This delegate method is executed when a notification is received while
     the app is in the foreground. Check with Chat to see whether it's
     appropriate to display the notification (or if the notification
     relates to information already being shown to the user).
    */
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler:
                                @escaping (UNNotificationPresentationOptions) -> Void) {

      let chat = ServiceCloud.shared().chatUI!

      // Show we display this notification?
      if (chat.shouldDisplayNotificationInForeground()) {

        // Display notification as an alert
        completionHandler(.alert)
      }
    }
    ```

    In Objective-C:

    ```java
    /**
     This delegate method is executed when the application launches as a result
     of the user interacting with a notification when it is in the background.
     The result of passing the notification to Chat is that we will
     maximize if the notification was scheduled as a result of a chat event.
    */
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center
    didReceiveNotificationResponse:(UNNotificationResponse *)response
             withCompletionHandler:(void(^)(void))completionHandler {

      SCSChatInterface *chat = [SCServiceCloud sharedInstance].chatUI;
      [chat handleNotification:response.notification];
    }

    /**
     This delegate method is executed when a notification is received while
     the app is in the foreground. Check with Chat to see whether it's
     appropriate to display the notification (or if the notification
     relates to information already being shown to the user).
    */
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center
           willPresentNotification:(UNNotification *)notification
             withCompletionHandler:
               (void (^)(UNNotificationPresentationOptions options))completionHandler {

      SCSChatInterface *chat = [SCServiceCloud sharedInstance].chatUI;

      // Show we display this notification?
      if ([chat shouldDisplayNotificationInForeground]) {

        // Display notification as an alert
        completionHandler(UNNotificationPresentationOptionAlert);
      }
    }
    ```
