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.
Swift
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if let userInfo = response.notification.request.content.userInfo as? [String : Any], let messageObject = userInfo["message"] as? [String:Any] { print("didReceive: \(userInfo)") if let baseMessage = CometChat.processMessage(messageObject).0 { switch baseMessage.messageCategory { case .message: print("Message Object Received: \(String(describing: (baseMessage as? TextMessage)?.stringValue()))") case .action: break case .call: break case .custom: break @unknown default: break } } } completionHandler() }
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.
In this method you need to fire notification after you receive the User or Group Object.
In Notification’s user info you can pass User or Group Object to that desired notification.