Class NotificationCenter
Send, receive and manage notifications. Must be initialized before use. See Initialize(NotificationCenterArgs).
Inherited Members
Namespace: Unity.Notifications
Assembly: Unity.Notifications.Unified.dll
Syntax
public static class NotificationCenter
Properties
LastRespondedNotification
Returns last notification tapped by user, or null.
Declaration
[Obsolete("Use QueryLastRespondedNotification instead.")]
public static Notification? LastRespondedNotification { get; }
Property Value
Type | Description |
---|---|
Notification? |
Methods
CancelAllDeliveredNotifications()
Remove all already delivered notifications.
Declaration
public static void CancelAllDeliveredNotifications()
CancelAllScheduledNotifications()
Cancel all future notifications.
Declaration
public static void CancelAllScheduledNotifications()
CancelDeliveredNotification(int)
Cancel delivered notification. Removes notification from the tray.
Declaration
public static void CancelDeliveredNotification(int id)
Parameters
Type | Name | Description |
---|---|---|
int | id | ID of the notification to cancel. |
CancelScheduledNotification(int)
Cancel a scheduled notification.
Declaration
public static void CancelScheduledNotification(int id)
Parameters
Type | Name | Description |
---|---|---|
int | id | ID of the notification to cancel. |
ClearBadge()
Clear Application badge. iOS only. iOS applications can set numeric badge on app icon. Calling this method removes that badge. On Android badge is removed automatically when notifications are removed.
Declaration
public static void ClearBadge()
Initialize(NotificationCenterArgs)
Initializes notification center with given arguments. On Android it will also create notification channel if arguments are set accordingly.
Declaration
public static void Initialize(NotificationCenterArgs args)
Parameters
Type | Name | Description |
---|---|---|
NotificationCenterArgs | args | Arguments for initialization. |
OpenNotificationSettings(NotificationSettingsSection)
Opens settings for the application. If possible, will try to navigate as close to requested section as it can. On iOS and Android prior to 8.0 will open settings for the application. Since Android 8.0 will open notification settings for either application or the default channel.
Declaration
public static void OpenNotificationSettings(NotificationSettingsSection section = NotificationSettingsSection.Application)
Parameters
Type | Name | Description |
---|---|---|
NotificationSettingsSection | section | The section to navigate to. |
QueryLastRespondedNotification()
Queries for the last notification used to open the app.
Declaration
public static QueryLastRespondedNotificationOp QueryLastRespondedNotification()
Returns
Type | Description |
---|---|
QueryLastRespondedNotificationOp | An asynchronous operation that can be used in a coroutine to retrieve the notification. |
RequestPermission()
Request for users permission to post notifications. Requests users permission to send notifications. Unless already allowed or permanently denied, shows UI to the user. Users can revoke permission in Settings while app is not running.
Declaration
public static NotificationsPermissionRequest RequestPermission()
Returns
Type | Description |
---|---|
NotificationsPermissionRequest | An object for tracking the request and obtaining results. |
Remarks
Before Android 13 no permission is required.
ScheduleNotification<T>(Notification, string, T)
Schedule notification to be shown in the future. Allows to explicitly specify the category to send notification to. On Android it is notification channel. Channel or category has to be created manually using AndroidNotificationCenter and iOSNotificationCenter respectively.
Declaration
public static int ScheduleNotification<T>(Notification notification, string category, T schedule) where T : NotificationSchedule
Parameters
Type | Name | Description |
---|---|---|
Notification | notification | Notification to send. |
string | category | Identifier for iOS category or Android channel. |
T | schedule | Schedule, specifying, when notification should be shown. |
Returns
Type | Description |
---|---|
int | Notification identifier. |
Type Parameters
Name | Description |
---|---|
T | Type of the schedule, usually deduced from actually passed one. |
ScheduleNotification<T>(Notification, T)
Schedule notification to be shown in the future.
Declaration
public static int ScheduleNotification<T>(Notification notification, T schedule) where T : NotificationSchedule
Parameters
Type | Name | Description |
---|---|---|
Notification | notification | Notification to send. |
T | schedule | Schedule, specifying, when notification should be shown. |
Returns
Type | Description |
---|---|
int | Notification identifier. |
Type Parameters
Name | Description |
---|---|
T | Type of the schedule, usually deduced from actually passed one. |
Events
OnNotificationReceived
An event that fires when notification is received. Application must be running for this event to work. On Android this even fires if application is in foreground or when it's brought back from background. On iOS this even only fires when notification is received while app is in foreground.
Declaration
public static event NotificationCenter.NotificationReceivedCallback OnNotificationReceived
Event Type
Type | Description |
---|---|
NotificationCenter.NotificationReceivedCallback |
Remarks
This event is the same as AndroidNotificationCenter.OnNotificationReceived and iOSNotificationCenter.OnNotificationReceived.