This Unity project demonstrates how to use the Unity Mobile Notifications API in real-world use cases.
The primary component of the wrapper is the Game Notifications Manager. It is the interface through which you can schedule cross-platform local notifications.
var channel = new GameNotificationChannel(ChannelId, "Default Game Channel", "Generic notifications");
manager.Initialize(channel);
var notification = manager.CreateNotification();
(Note that the wrapper might return a null object on some platforms. Check for null before continuing.)
notification.Title = title;
notification.Body = body;
notification.DeliveryTime = deliveryTime;
manager.ScheduleNotification(notification);
The Manager saves a small file to disk whenever backgrounding so that it can keep track of notifications that were published and scheduled in previous sessions.
The manager features several operation modes that control its behaviour. The default operation mode has queueing, foreground clearing and automatic rescheduling all on.
No queueing
The wrapper immediately schedules messages with the underlying operating system.
Queuing
The wrapper only schedules messages with the OS when backgrounding. The system will also (optionally, but on by default) have the ability to calculate badge numbers automatically in this mode. If you don't provide any badge numbers manually with your notifications, the wrapper will set the badge numbers so that they increment based on the scheduled time of each notification.
Foreground clearing
The wrapper will remove all scheduled messages when the app comes into the foreground.
Automatic rescheduling
If this is set, after clearing all messages when foregrounding, the wrapper will go through all notifications marked this way, and put them back in the queue for delivery.
To configure a notification for rescheduling:
var notificationToDisplay = manager.ScheduleNotification(notification);
notificationToDisplay.Reschedule = true;
This Sample was developed in conjunction with 24 Bit Games. www.24bit.games