---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowChatServiceDelegate protocol - iOS

# NowChatServiceDelegate protocol - iOS {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

The NowChatServiceDelegate protocol provides callbacks for
notification of actions within the NowChatService such as a request to open a
URL or dismiss the chat view controller.

## NowChatServiceDelegate - chatService(_chatService: NowChatService, didRequestOpenUrlurl:
URL) {#ariaid-title2}

Callback that notifies the host application that the specified chat service received a
request to open a URL. This callback is usually triggered by a user tapping on a link in the
chat UI. It is the host application's responsibility to handle opening the URL or ignore the
request.
{#NCSD-chatService_O_S__table_alb_31w_wqb__entry__3}

| Name | Type | Description |
|-|-|-|
| chatService | [NowChatService](https://servicenow-prod.fluidtopics.net/V5g0WnyO4pFrtA3ShZvYew#NowChatServiceiOSAPI "The NowChatService class provides Virtual and Live Agent chat capabilities.") | NowChatService object making the request. |
| didRequestOpenUrl url | URL | URL that the service has requested to open. |
[Table 1. Parameters]

{#NCSD-chatService_O_S__table_alb_31w_wqb} {#NCSD-chatService_O_S__table_blb_31w_wqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 2. Returns]

{#NCSD-chatService_O_S__table_blb_31w_wqb}  
The following code example shows how to call this function.

    func chatService(_ chatService: NowChatService, didRequestOpenUrl url: URL) {
      var updatedViewState = makeViewState()
      updatedViewState.urlToOpen = url
      viewState = updatedViewState
    }

## NowChatServiceDelegate - chatService(_chatService: NowChatService, systemThemeDidChange traitCollection: UITraitCollection) {#ariaid-title3}

Callback that notifies the host application that the system chat theme changed.
{#NCSD-chatService_O_B_O__table_uhw_s1w_x2c__entry__3}

| Name | Type | Description |
|-|-|-|
| chatService | [NowChatService](https://servicenow-prod.fluidtopics.net/V5g0WnyO4pFrtA3ShZvYew#NowChatServiceiOSAPI "The NowChatService class provides Virtual and Live Agent chat capabilities.") | NowChatService object making the request. |
| traitCollection | [UITraitCollection](https://developer.apple.com/documentation/uikit/uitraitcollection) | UITraitCollection that contains the new theme. |
[Table 3. Parameters]

{#NCSD-chatService_O_B_O__table_uhw_s1w_x2c} {#NCSD-chatService_O_B_O__table_vhw_s1w_x2c__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 4. Returns]

{#NCSD-chatService_O_B_O__table_vhw_s1w_x2c}  
The following code example shows how to override the systemThemeDidChange() delegate function to call the updateTheme() function to apply theme changes when the system theme changes.

    func chatService(_ chatService: any SnowChat.ChatServiceProvider, systemThemeDidChange traitCollection: UITraitCollection) {

      /// The corresponding updateTheme() method can be called here to change the UI theme based on System Theme
      chatService.updateTheme(theme: traitCollection.userInterfaceStyle == .dark ? DarkNowChatTheme() : LightNowChatTheme())
      print("System Theme Did Change)
    }

## NowChatServiceDelegate - chatServiceViewControllerWasDismissed(_chatService:
NowChatService) {#ariaid-title4}

Callback that notifies the host application that the chat view controller was
dismissed.
{#NCSD-chatServiceViewContDismiss_O__table_vs4_qbw_wqb__entry__3}

| Name | Type | Description |
|-|-|-|
| chatService | [NowChatService](https://servicenow-prod.fluidtopics.net/V5g0WnyO4pFrtA3ShZvYew#NowChatServiceiOSAPI "The NowChatService class provides Virtual and Live Agent chat capabilities.") | NowChatService object whose view controller was dismissed. |
[Table 5. Parameters]

{#NCSD-chatServiceViewContDismiss_O__table_vs4_qbw_wqb} {#NCSD-chatServiceViewContDismiss_O__table_ws4_qbw_wqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 6. Returns]

{#NCSD-chatServiceViewContDismiss_O__table_ws4_qbw_wqb}  
The following code example shows how to call this function.

    func chatServiceViewControllerWasDismissed(_ chatService: NowChatService) {
      resetChat()
    }

## NowChatServiceDelegate - didEndSessionWithId(sessionId: String) {#ariaid-title5}

Called when the chat screen is closed and the chat session ends.
Note:  
You must define the desired functionality for this callback by overriding the function as the default implementation simply prints the message "Chat Session ended with ID: \\(sessionId)".
{#NCSD-didEndSessionWId_S__table_j1t_hv2_52c__entry__3}

| Name | Type | Description |
|-|-|-|
| sessionId | String | Sys_id of the session that ended. Table: Conversation Session \[sys_cs_session\] |
[Table 7. Parameters]

{#NCSD-didEndSessionWId_S__table_j1t_hv2_52c} {#NCSD-didEndSessionWId_S__table_k1t_hv2_52c__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 8. Returns]

{#NCSD-didEndSessionWId_S__table_k1t_hv2_52c}  
The following code example shows where to place your code to override the default functionality.

    func chatService(_ chatService: NowChatService, didEndSessionWithId sessionId: String) {
      print("Chat Session ended with ID: \(sessionId)")
    }


