A Kotlin Multiplatform demo showing how to request notification permissions and trigger native local notifications on both Android and iOS — with all the logic written in Kotlin.
This demo proves that KMP isn’t just for sharing ViewModels, you can even handle notifications natively using expect/actual.
- ✅ Single Kotlin API for notifications
- 📱 Works on Android and iOS
- 🧩 Uses
expect/actualto access native notification frameworks - 🍏 Minimal Swift code — only an
AppDelegatefor iOS setup - ⚡ Fully functional local notifications demo
The shared module defines an expected class:
expect class NotificationService {
fun showNotification(
title: String,
message: String?
)
fun requestPermission(
activity: PlatformActivity,
onFinished: (Boolean) -> Unit
)
suspend fun areNotificationsEnabled(): Boolean
}Each platform provides its actual implementation.
- Uses
NotificationCompatto create and display notifications - Handles Android 13+ permission requests
- Creates a simple notification channel
- Uses
UNUserNotificationCenterandUIApplicationdirectly from Kotlin - Requests permission and sends notifications through iOS APIs
- Only requires a tiny bit of Swift in
AppDelegatefor delegate registration
A minimal interface with two buttons:
- Request Permission → calls
askForNotificationPermission - Show Notification → triggers
showNotification() - -ViewModel to call the service and observe if notifications are enabled
You can build it using:
- Compose Multiplatform for a unified UI
or - Native SwiftUI / Android XML — both work perfectly with this shared logic
- Android Studio Ladybug+ or later
- Xcode 15+
- Kotlin 2.0+
- Compose Multiplatform (optional) if you’re using shared UI
Just hit Run from Android Studio and tap the buttons.
Open the iOS app in Xcode once (to register the AppDelegate), then run:
./gradlew iosDeployIPhoneSimulatoror run it directly from Xcode.
Make sure to allow notifications when prompted.
When you press Show Notification, you’ll see:
“Hello, ${getPlatform().name}!” “This is a notification message.”
appearing natively on both platforms.
This project demonstrates how Kotlin Multiplatform lets you:
- Access native platform APIs directly from Kotlin
- Replace boilerplate Swift/Kotlin with a single shared implementation
- Keep full control while sharing real functionality
KMP is not just about shared logic — it’s about shared power ⚡
Built with ❤️ by KMP Bits
Follow more Kotlin Multiplatform content on: