Push notifications are supported on Android and iOS via the kmpnotifier-push-firebase module. On desktop and web, this module acts as a no-op mock.
1. Listen for Push Events
Register a PushListener using KMPNotifier.addPushListener to handle token updates and incoming messages. Available callbacks include onNewToken, onPushNotification, onPayloadData, and onPushNotificationWithPayloadData.
2. Platform Integration (Required)
You must call platform-specific hooks to ensure payloads are delivered correctly:
- Android: Call
KMPNotifier.onCreateOrOnNewIntent(intent) in your Activity's onCreate and onNewIntent. - iOS: Call
KMPNotifier.onApplicationDidReceiveRemoteNotification(userInfo:) in your app's didReceiveRemoteNotification method.
3. Token and Topic Management
All push notifier methods are suspend functions and must be called from a coroutine:
getToken(): Retrieves the current push token.deleteMyToken(): Deletes the current token (e.g., on logout).subscribeToTopic(topic): Subscribes to a Firebase topic.unSubscribeFromTopic(topic): Unsubscribes from a Firebase topic.
// Listening for push events
KMPNotifier.addPushListener(object : PushListener {
override fun onNewToken(token: String) {
println("onNewToken: $token")
}
override fun onPushNotification(title: String?, body: String?) {
println("Push received — title: $title, body: $body")
}
})
// Token management (inside a coroutine)
val token = KMPNotifier.firebasePushNotifier.getToken()
KMPNotifier.firebasePushNotifier.subscribeToTopic("new_users")