Unity-Technologies / NotificationsSamples

Sample project for Unity Notifications
Other
282 stars 51 forks source link

Mobile Notifications Samples & Wrapper

This Unity project demonstrates how to use the Unity Mobile Notifications API in real-world use cases.

Overview: the Game Notifications Manager

The primary component of the wrapper is the Game Notifications Manager. It is the interface through which you can schedule cross-platform local notifications.

Usage

  1. Add the Game Notifications Manager to a Game Object (Note that the Manager's lifetime is currently limited to one scene. Up to you to add a DontDestroyOnLoad)
  2. Reference it from a game script that will send notifications.
  3. Initialize the Manager. Provide at least one channel if targeting Android. This should only be done once per application session.
var channel = new GameNotificationChannel(ChannelId, "Default Game Channel", "Generic notifications");
manager.Initialize(channel);
  1. Create a new notification:
var notification = manager.CreateNotification();

(Note that the wrapper might return a null object on some platforms. Check for null before continuing.)

  1. Fill in the important fields
notification.Title = title;
notification.Body = body;
notification.DeliveryTime = deliveryTime;
  1. Schedule the notification.
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.

Operation Modes

The manager features several operation modes that control its behaviour. The default operation mode has queueing, foreground clearing and automatic rescheduling all on.

var notificationToDisplay = manager.ScheduleNotification(notification);
notificationToDisplay.Reschedule = true;

Demo Notes

Credits

This Sample was developed in conjunction with 24 Bit Games. www.24bit.games