-
Notifications
You must be signed in to change notification settings - Fork 0
In app notifications
This guide is meant for Kaleyra Video 4.0 version. If you are using a 3.x version please take a look this guide instead.
The InAppNotifications component is responsible for managing when in-app notifications should be displayed, where they should appear on screen and respond to user interactions. It provides a convenient API you can use to be notified when a user interacts with one in-app notification. InAppNotifications clients are responsible for enabling or disabling in-app notifications, they are also responsible for updating the user interface of their app, navigating the user to the Kaleyra Video provided app screens when the user interacts with any notification. We will guide you through all the steps required to integrate Kaleyra Video in-app notifications in your app in a moment, but first let us point out what in-app notifications are not. In-app notifications are not a replacement for standard push notifications, nor they are related whatsoever.
In order to start showing in-app notifications to users, the InAppNotifications must be started. You can retrieve an InAppNotifications instance from the Conversation instance, then you can start it calling the start
method. We strongly suggest you to do it in one of your main view controllers after the user as signed-in.
The following snippets of code will show you how to start the notifications coordinator:
class MyViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
KaleyraVideo.instance.conversation?.notifications.delegate = self
KaleyraVideo.instance.conversation?.notifications.start()
}
}
As you might have noticed we also registered the view controller as an InAppNotificationsDelegate. Conforming as delegate is mandatory if you want to react to in-app notifications being touched by your users.
Once started, in-app notifications are enabled so when a new chat message is received your user will be presented an in-app notification when your user is not facing the chat screen.
Don't forget to stop the InAppNotifications when you don't wont your user to be bothered with in-app notifications or when your user signs off. To do that the InAppNotifications provides a stop
method. The following snippets of code will stop the coordinator when the view controller is dismissed pretending the used signed off.
class MyViewController: UIViewController {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
KaleyraVideo.instance.conversation?.notifications.stop()
}
}
In-app chat notifications are presented to your user when she/he is not facing the ChatViewController for the chat channel where the message belongs to. Whenever your user touches the notification, the InAppNotificationsDelegate onTouch(_ notification: ChatNotification)
method is called. You are responsible for handling that interaction presenting a ChatViewController, if you are not acquainted with this topic please head over to our Opening a chat guide.
The following snippets of code will show you how to respond to a chat notification being touched by a user:
extension MyViewController: InAppNotificationsDelegate {
func onTouch(_ notification: ChatNotification) {
if presentedViewController is ChatViewController {
presentedViewController?.dismiss(animated: true) { [weak self] in
self?.presentChat(from: notification)
}
} else {
presentChat(from: notification)
}
}
private func presentChat(from notification: ChatNotification) {
let controller = ChatViewController(intent: .chat(id: notification.chatId), configuration: .init())
controller.delegate = self
present(controller, animated: true)
}
}
Looking for other platforms? Take a look at Android, Flutter, ReactNative, Ionic / Cordova. Anything unclear or inaccurate? Please let us know by submitting an Issue or write us here.