Skip to main content
Quick Reference for AI Agents & Developers
  • Requires: CometChat SDK and UI Kit both configured
  • Implementation: Handle notification tap in AppDelegate or SceneDelegate
  • Parse payload: Extract sender UID or group GUID from notification payload
  • Launch: Present CometChatMessages view controller with user/group
  • Related: Receive Message · Push Notifications · UI Kit
This guide helps you to launch a chat window from the UI Kit library on receiving a new message notification.
CometChat SDK & UI Kit both need to be configured before launching the chat window.

Step 1. Process push notification payload and grab User or Group object

To present a chat window, firstly you will need a User or a Group object. You can grab this from the push notification payload itself of incoming message notification. You need to call CometChat.processMessage() method to process push notification payload.
userInfo Dictionary Structure (User Message):message Dictionary:sender Dictionary:aps Dictionary:alert Dictionary:
userInfo Dictionary Structure (Group Message):message Dictionary:sender Dictionary:receiver Dictionary (Group):aps Dictionary:alert Dictionary:
Method Signature:Return Tuple Structure:TextMessage Object Properties (when type is “text”):sender User Object:receiver Object (User or Group):When receiverType is .user:When receiverType is .group:MessageCategory Enum Values:ReceiverType Enum Values:

Step 2. Launch Chat Window

You can launch the chat window from your base view controller after you tap on the Message Notification. This method uses NotificationCenter to trigger and present a chat window.
  1. In this method you need to fire notification after you receive the User or Group Object.
  2. In Notification’s user info you can pass User or Group Object to that desired notification.

Trigger notification from App Delegate

NotificationCenter.default.post() Method Parameters:userInfo Dictionary Structure:User Object Properties:UserStatus Enum Values:Notification Dispatch Flow:
NotificationCenter.default.post() Method Parameters:userInfo Dictionary Structure:Group Object Properties:GroupType Enum Values:MemberScope Enum Values:Notification Dispatch Flow:
  1. On the other hand, you need to observe for the above notification in your base view controller.
  1. Base view controller is a controller that launches immediately after the app delegate.
  2. Base view controller should be present to observe the notification when notification fires.
  3. If the view controller is not present in the memory when a new notification receives, then it won’t launch Chat Window.

Observe notification in Base View Controller

Add selector method & Launch Chat Window

NSNotification Object Structure:userInfo Dictionary:Group Object Properties:CometChatMessageList Configuration:set(conversationWith:type:) Parameters:Selector Method Flow:
NSNotification Object Structure:userInfo Dictionary:User Object Properties:CometChatMessageList Configuration:set(conversationWith:type:) Parameters:Selector Method Flow: