Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

NowChatServiceDelegate protocol- iOS

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.

Parent Topic:Mobile SDK - iOS

NowChatServiceDelegate - chatService(_chatService: NowChatService, didRequestOpenUrlurl: URL)

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.

NameTypeDescription
chatServiceNowChatServiceNowChatService object making the request.
didRequestOpenUrl urlURLURL that the service has requested to open.
TypeDescription
None 

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)

Callback that notifies the host application that the system chat theme changed.

NameTypeDescription
chatServiceNowChatServiceNowChatService object making the request.
traitCollectionUITraitCollectionUITraitCollection that contains the new theme.
TypeDescription
None 

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)

Callback that notifies the host application that the chat view controller was dismissed.

NameTypeDescription
chatServiceNowChatServiceNowChatService object whose view controller was dismissed.
TypeDescription
None 

The following code example shows how to call this function.

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

NowChatServiceDelegate - didEndSessionWithId(sessionId: String)

Called when the chat screen is closed and the chat session ends.

Note: You can define the desired functionality for this callback by overriding the function.

NameTypeDescription
sessionIdStringSys\_id of the session that ended.Table: Conversation Session \[sys\_cs\_session\]
TypeDescription
None 

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)")
}