Skip to content

Local Notification Service and Scheduling Local Notifications

LocalNotificationService is a wrapper for Unity's standard methods in the Unity.Notifications namespace, and allows an IdleKit project to schedule local device notifications at a certain time in the future. The service supports both Android and iOS.

Scheduling Local Notifications

In order to schedule a notification at a certain time in the future use the ScheduleLocalNotification(...) method with a time fireTime when you want the local notification to fire. A simple way to schedule a local notification is to resolve the System Clock and then use its NowAsUtc method to retrieve the current UTC time. Then use the AddSeconds(seconds) AddMinutes(...) or a similar extension method to add the desired amount of time to the current UTC time, and pass the resulting DateTime into the ScheduleLocalNotification(...) method as your fireTime.

Reacting to Local Notifications

When the device receives a notification you can react to that in your application by subscribing to the OnAndroidLocalNotificationReceived or the OnIOSNotificationReceived actions in the LocalNotificationService depending on your platform. Note that these callbacks react to the notification being shown to the user, as opposed to the player clicking the notification. Please refer to the Unity's documentation for the Mobile Notifications service in order to react to opened notifications within the app: https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.4/manual/index.html

Adding Custom Icons to Notifications on Android

On Android it is possible to add a custom icon to your local notification, in place of the app icon. In order to do that use the smallIcon or largeIcon parameter in the ScheduleLocalNotification(...) method. The icons are passed in as strings, which are defined in Unity in Project Settings in the following window.

localnotificationservice

On iOS custom icons in notifications are not supported.

For any additional information on local notifications, please refer to Unity's documentation for the Mobile Notifications service: https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.4/manual/index.html