Manage & Broadcast Local Notifications
Manage & Broadcast Local Notifications
Use this component to broadcast a local notification on your device.
To get started using it, you must use KmpLocalNotifications. All functions are thread safe and main thread safe.
Broadcast a local notification
_1KmpLocalNotifications.sendNotification("Notification Title", "Notification Message to send to the user")
Broadcast repeated Notifications
To broadcast notifications on an interval, or a loop, please use these functions:
_14/**_14 * Schedules an alarm, and broadcasts a local notification with the specified Title & Message, after duration in milliseconds has passed_14 * @param durationMS milliseconds until the local notification is triggered_14 * */_14_14 KmpLocalNotifications.scheduleAlarmNotification(durationMS: Long, title: String, message: String)_14_14/**_14 * Schedules a repeating alarm, and broadcasts a local notification with the specified Title & Message, after duration in milliseconds has passed_14 * @param durationMS milliseconds until the local notification is triggered, and will repeat after every intervalMs set_14 * @param intervalMs the interval in milliseconds between repeats_14 * */_14_14 KmpLocalNotifications.scheduleAlarmNotificationRepeating(durationMS: Long, intervalMs: Long, title: String, message: String)
Cancelling any Repeating Notifications
If you have any scheduled alarms running on a repeat, please use the below function:
_1KmpLocalNotifications.cancelAllRepeatingAlarms()
Scheduling a Local Notification
If you need to schedule a local notification at a future date, regardless if the app is running, closed or in the background. Please use the following function:
_2val scheduleMs = 5000 // duration in milliseconds when the local notification will get triggered_2KmpLocalNotifications.scheduleAlarmNotification(scheduleMs, "Notification Title", "Notification Message to send to the user")
Controlling precision of scheduled notifications (Android Only)
Some devices might not support exact broadcasting. Meaning if you schedule a notification to run in 5 seconds from now, the device you are running on might not support a 5 seconds exact broadcast. To control this you can use on your android source set, or android client module.
_1KmpLocalNotifications.allowSetExact(false) // true to enable precision
The default value for exact is true. Using KmpLocalNotifications.allowSetExact(false) will allow the device to broadcast the notification when its ready (but close to when the duration has expired).
Android Setup
For android please add this into your manifest:
_1<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
And inside your android manifest, please add these permissions (in order to use exact alarms. This permission is required for exact scheduling to work):
_1 <uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
To configure your local notification icon please add this in your Activity/Application or your Android Source Set:
_2// icon is your resource drawable for your app or the icon you wish to use for your notifications_2KmpLocalNotifications.setNotificationIcon(icon: Int)
iOS Setup
None Required