UTNotifications  1.8
Professional Local & Push Notification Plugin
Public Member Functions | Protected Member Functions | Properties | Events | List of all members
UTNotifications.Manager Class Referenceabstract

The main class providing UTNotifications API. More...

Inheritance diagram for UTNotifications.Manager:

Public Member Functions

bool Initialize (bool willHandleReceivedNotifications, int startId=0, bool incrementalId=false)
 Initializes the Manager. It's safe to call more than once. More...
 
void PostLocalNotification (string title, string text, int id, IDictionary< string, string > userData=null, string notificationProfile=null, int badgeNumber=Notification.BADGE_NOT_SPECIFIED, ICollection< Button > buttons=null)
 Posts a local notification immediately (see remarks). More...
 
void PostLocalNotification (LocalNotification notification)
 Posts a local notification immediately (see remarks). More...
 
void ScheduleNotification (int triggerInSeconds, string title, string text, int id, IDictionary< string, string > userData=null, string notificationProfile=null, int badgeNumber=Notification.BADGE_NOT_SPECIFIED, ICollection< Button > buttons=null)
 Schedules a local notification. More...
 
void ScheduleNotification (DateTime triggerDateTime, string title, string text, int id, IDictionary< string, string > userData=null, string notificationProfile=null, int badgeNumber=Notification.BADGE_NOT_SPECIFIED, ICollection< Button > buttons=null)
 Schedules a local notification. More...
 
void ScheduleNotification (ScheduledNotification notification)
 Schedules a local notification (either single-time or repeating). More...
 
void ScheduleNotificationRepeating (int firstTriggerInSeconds, int intervalSeconds, string title, string text, int id, IDictionary< string, string > userData=null, string notificationProfile=null, int badgeNumber=Notification.BADGE_NOT_SPECIFIED, ICollection< Button > buttons=null)
 Schedules a repeating local notification. More...
 
void ScheduleNotificationRepeating (DateTime firstTriggerDateTime, int intervalSeconds, string title, string text, int id, IDictionary< string, string > userData=null, string notificationProfile=null, int badgeNumber=Notification.BADGE_NOT_SPECIFIED, ICollection< Button > buttons=null)
 Schedules a repeating local notification. More...
 
abstract bool NotificationsEnabled ()
 Checks whether notifications are enabled. More...
 
abstract bool NotificationsAllowed ()
 Checks whether notifications are allowed to be shown by your app in the OS settings/notifications permission system dialog. More...
 
abstract void SetNotificationsEnabled (bool enabled)
 Enables or disables showing any notifications (doesn't affect the OS settings). More...
 
abstract bool PushNotificationsEnabled ()
 Checks if push notifications are enabled on the given platform. More...
 
abstract bool SetPushNotificationsEnabled (bool enable)
 Enables push notifications, if any are configured and supported on the given platform (doesn't affect the OS settings). More...
 
void CancelNotification (int id)
 Cancels the notification with the specified ID (ignored if the specified notification is not found). More...
 
abstract void HideNotification (int id)
 Hides the notification with the specified ID (ignored if the specified notification is not found). More...
 
void CancelAllNotifications ()
 Cancels all the notifications.

See also
CancelNotification
More...
 
abstract void HideAllNotifications ()
 Hides all the notifications.

See also
HideNotification
More...
 
abstract int GetBadge ()
 Returns the app icon badge value when supported and 0 otherwise. More...
 
abstract void SetBadge (int bandgeNumber)
 Sets the app icon badge value when supported. More...
 
abstract void SubscribeToTopic (string topic)
 Subscribes to an FCM topic. More...
 
abstract void UnsubscribeFromTopic (string topic)
 Unsubscribes from an FCM topic. More...
 
delegate void OnInitializedHandler ()
 
delegate void OnSendRegistrationIdHandler (string providerName, string registrationId)
 
delegate void OnPushRegistrationFailedHandler (string error)
 
delegate void OnNotificationClickedHandler (ReceivedNotification notification)
 
delegate void OnNotificationsReceivedHandler (IList< ReceivedNotification > receivedNotifications)
 

Protected Member Functions

abstract bool InitializeImpl (bool willHandleReceivedNotifications, int startId, bool incrementalId)
 
abstract void PostLocalNotificationImpl (LocalNotification notification)
 
abstract void ScheduleNotificationImpl (ScheduledNotification notification)
 
abstract void ScheduleNotificationRepeatingImpl (ScheduledRepeatingNotification notification)
 
abstract void CancelNotificationImpl (int id)
 
abstract void CancelAllNotificationsImpl ()
 
abstract bool CleanupObsoleteScheduledNotifications (List< ScheduledNotification > scheduledNotifications)
 
bool OnSendRegistrationIdHasSubscribers ()
 
void _OnSendRegistrationId (string providerName, string registrationId)
 
bool OnPushRegistrationHasSubscribers ()
 
void _OnPushRegistrationFailed (string error)
 
bool OnNotificationClickedHasSubscribers ()
 
void _OnNotificationClicked (ReceivedNotification notification)
 
bool OnNotificationsReceivedHasSubscribers ()
 
void _OnNotificationsReceived (IList< ReceivedNotification > receivedNotifications)
 
virtual void OnDestroy ()
 
void NotSupported (string feature=null)
 
bool CheckInitialized ()
 

Properties

static Manager Instance [get]
 This is how you access the one and only instance of the Manager. More...
 
bool Initialized [get, protected set]
 true if the Manager is initialized. More...
 
ICollection< ScheduledNotificationScheduledNotifications [get]
 Returns a collection of all currently scheduled local notifications, including one-time and repeating notifications. One-time notifications that have already been shown are not included. More...
 

Events

OnInitializedHandler OnInitialized
 Occurs when the Manager get initialized. More...
 
OnSendRegistrationIdHandler OnSendRegistrationId
 Occurs when the registrationId for push notifications is received and should be sent to your server. More...
 
OnPushRegistrationFailedHandler OnPushRegistrationFailed
 Occurs if registering for push notifications is failed. More...
 
OnNotificationClickedHandler OnNotificationClicked
 Occurs when a user tapped/clicked on a notification or its button. More...
 
OnNotificationsReceivedHandler OnNotificationsReceived
 Occurs when one or more local, scheduled or push notifications are received. More...
 

Detailed Description

The main class providing UTNotifications API.

It's a singleton which automatically creates a single GameObject "UTNotificationsManager" which is not destroyed on a scene loading.

Usage:

  1. You might want to subscribe to a number of UTNotifications.Manager events, which is important to do BEFORE initializing the manager.
    See also
    Manager.OnInitialized, Manager.OnSendRegistrationId, Manager.OnPushRegistrationFailed, Manager.OnNotificationClicked, Manager.OnNotificationsReceived
  2. Call UTNotifications.Manager.Instance.Initialize in order to initialize the notifications system.
    See also
    Manager.Initialize
  3. Now you can start using all the UTNotifications.Manager API methods (see the methods description for further information).

Member Function Documentation

◆ CancelAllNotifications()

void UTNotifications.Manager.CancelAllNotifications ( )

Cancels all the notifications.

See also
CancelNotification

◆ CancelNotification()

void UTNotifications.Manager.CancelNotification ( int  id)

Cancels the notification with the specified ID (ignored if the specified notification is not found).

If the specified notification is scheduled or repeating all the future shows will be also canceled.

◆ GetBadge()

abstract int UTNotifications.Manager.GetBadge ( )
pure virtual

Returns the app icon badge value when supported and 0 otherwise.

◆ HideAllNotifications()

abstract void UTNotifications.Manager.HideAllNotifications ( )
pure virtual

Hides all the notifications.

See also
HideNotification

Not supported and will be ignored on Windows Store.

◆ HideNotification()

abstract void UTNotifications.Manager.HideNotification ( int  id)
pure virtual

Hides the notification with the specified ID (ignored if the specified notification is not found).

If the specified notification is scheduled or repeating, all the future shows will remain scheduled. Not supported and will be ignored on Windows Store/Universal Windows Platform.

◆ Initialize()

bool UTNotifications.Manager.Initialize ( bool  willHandleReceivedNotifications,
int  startId = 0,
bool  incrementalId = false 
)

Initializes the Manager. It's safe to call more than once.

Parameters
willHandleReceivedNotificationsSet to true to be able to handle received notifications.
See also
OnNotificationsReceived
startIdID of a first received push notification
incrementalIdIf set to true, each received push notfication will have an ID = previous push notification ID + 1. Otherwise all received push notifications will have ID = startId
Returns
true, if initialized successfully, false otherwise.

Please set willHandleReceivedNotifications to true only if you will handle received notifications using OnNotificationsReceived. Otherwise, all the received notifications will be stored and never cleaned. If incrementalId is false (default value), then new push notifications will replace old ones on Android so only one push notification can be shown at a time, unless their ids are specified in their data.

◆ NotificationsAllowed()

abstract bool UTNotifications.Manager.NotificationsAllowed ( )
pure virtual

Checks whether notifications are allowed to be shown by your app in the OS settings/notifications permission system dialog.

◆ NotificationsEnabled()

abstract bool UTNotifications.Manager.NotificationsEnabled ( )
pure virtual

Checks whether notifications are enabled.

◆ PostLocalNotification() [1/2]

void UTNotifications.Manager.PostLocalNotification ( string  title,
string  text,
int  id,
IDictionary< string, string >  userData = null,
string  notificationProfile = null,
int  badgeNumber = Notification.BADGE_NOT_SPECIFIED,
ICollection< Button buttons = null 
)

Posts a local notification immediately (see remarks).

Parameters
titleThe notification title.
textThe notification text.
idThe notification ID (any notifications with the same id will be replaced by this one).
See also
CancelNotification, HideNotification
userData(Optional) A custom IDictionary<string, string> that can be received in OnNotificationsReceived.
See also
OnNotificationsReceived
notificationProfile(Optional) The name of the notification profile (sound, icon and other notification attributes).
badgeNumber(Optional) The badge number, to be displayed on top of application icon, when supported. Use Notification.BADGE_NOT_SPECIFIED (default) to keep previous value, 0 to hide the badge.
buttons(Optional) A collection of custom buttons (Android only, ignored on the rest platforms).

Note that with the default settings you will not be able to see or hear any immediate notifications on any of the supported platforms, because notifications are not shown while the application is running by default. You can modify this behaviour in UTNotifications Settings: Common Android Settings -> Show Notifications and Windows Store Settings -> Notify only when app is closed or hidden. Unfortunately, iOS doesn’t allow to control it: you can never see any notifications while the app is running on iOS.

◆ PostLocalNotification() [2/2]

void UTNotifications.Manager.PostLocalNotification ( LocalNotification  notification)

Posts a local notification immediately (see remarks).

Parameters
notificationA UTNotifications.LocalNotification to post.

Note that with the default settings you will not be able to see or hear any immediate notifications on any of the supported platforms, because notifications are not shown while the application is running by default. You can modify this behaviour in UTNotifications Settings: Common Android Settings -> Show Notifications and Windows Store Settings -> Notify only when app is closed or hidden. Unfortunately, iOS doesn’t allow to control it: you can never see any notifications while the app is running on iOS.

◆ PushNotificationsEnabled()

abstract bool UTNotifications.Manager.PushNotificationsEnabled ( )
pure virtual

Checks if push notifications are enabled on the given platform.

Returns
true, if notifications are enabled, false otherwise.

◆ ScheduleNotification() [1/3]

void UTNotifications.Manager.ScheduleNotification ( int  triggerInSeconds,
string  title,
string  text,
int  id,
IDictionary< string, string >  userData = null,
string  notificationProfile = null,
int  badgeNumber = Notification.BADGE_NOT_SPECIFIED,
ICollection< Button buttons = null 
)

Schedules a local notification.

Parameters
triggerInSecondsSeconds value from now when the notification will be shown.
titleThe notification title.
textThe notification text.
idThe notification ID (any notifications with the same id will be replaced by this one).
See also
CancelNotification, HideNotification
userData(Optional) A custom IDictionary<string, string> that can be received in OnNotificationsReceived.
See also
OnNotificationsReceived
notificationProfile(Optional) The name of the notification profile (sound, icon and other notification attributes).
badgeNumber(Optional) The badge number, to be displayed on top of application icon, when supported. Use Notification.BADGE_NOT_SPECIFIED (default) to keep previous value, 0 to hide the badge.
buttons(Optional) A collection of custom buttons (Android only, ignored on the rest platforms).

◆ ScheduleNotification() [2/3]

void UTNotifications.Manager.ScheduleNotification ( DateTime  triggerDateTime,
string  title,
string  text,
int  id,
IDictionary< string, string >  userData = null,
string  notificationProfile = null,
int  badgeNumber = Notification.BADGE_NOT_SPECIFIED,
ICollection< Button buttons = null 
)

Schedules a local notification.

Parameters
triggerDateTimeDateTime value when the notification will be shown.
titleThe notification title.
textThe notification text.
idThe notification ID (any notifications with the same id will be replaced by this one).
See also
CancelNotification, HideNotification
userData(Optional) A custom IDictionary<string, string> that can be received in OnNotificationsReceived.
See also
OnNotificationsReceived
notificationProfile(Optional) The name of the notification profile (sound, icon and other notification attributes).
badgeNumber(Optional) The badge number, to be displayed on top of application icon, when supported. Use Notification.BADGE_NOT_SPECIFIED (default) to keep previous value, 0 to hide the badge.
buttons(Optional) A collection of custom buttons (Android only, ignored on the rest platforms).

◆ ScheduleNotification() [3/3]

void UTNotifications.Manager.ScheduleNotification ( ScheduledNotification  notification)

Schedules a local notification (either single-time or repeating).

Parameters
notificationA UTNotifications.ScheduledNotification or UTNotifications.ScheduledRepeatingNotification to schedule.

◆ ScheduleNotificationRepeating() [1/2]

void UTNotifications.Manager.ScheduleNotificationRepeating ( int  firstTriggerInSeconds,
int  intervalSeconds,
string  title,
string  text,
int  id,
IDictionary< string, string >  userData = null,
string  notificationProfile = null,
int  badgeNumber = Notification.BADGE_NOT_SPECIFIED,
ICollection< Button buttons = null 
)

Schedules a repeating local notification.

Parameters
firstTriggerInSecondsSeconds value from now when the notification will be shown the first time.
intervalSecondsSeconds between the notification shows (see remarks).
titleThe notification title.
textThe notification text.
idThe notification ID (any notifications with the same id will be replaced by this one).
See also
CancelNotification, HideNotification
userData(Optional) A custom IDictionary<string, string> that can be received in OnNotificationsReceived.
See also
OnNotificationsReceived
notificationProfile(Optional) The name of the notification profile (sound, icon and other notification attributes).
badgeNumber(Optional) The badge number, to be displayed on top of application icon, when supported. Use Notification.BADGE_NOT_SPECIFIED (default) to keep previous value, 0 to hide the badge.
buttons(Optional) A collection of custom buttons (Android only, ignored on the rest platforms).

Please note that the actual interval may be different. On iOS there are only fixed options like every minute, every day, every week and so on. So the provided intervalSeconds value will be approximated by one of the available options.

◆ ScheduleNotificationRepeating() [2/2]

void UTNotifications.Manager.ScheduleNotificationRepeating ( DateTime  firstTriggerDateTime,
int  intervalSeconds,
string  title,
string  text,
int  id,
IDictionary< string, string >  userData = null,
string  notificationProfile = null,
int  badgeNumber = Notification.BADGE_NOT_SPECIFIED,
ICollection< Button buttons = null 
)

Schedules a repeating local notification.

Parameters
firstTriggerDateTimeDateTime value when the notification will be shown the first time.
intervalSecondsSeconds between the notification shows (see remarks).
titleThe notification title.
textThe notification text.
idThe notification ID (any notifications with the same id will be replaced by this one).
See also
CancelNotification, HideNotification
userData(Optional) A custom IDictionary<string, string> that can be received in OnNotificationsReceived.
See also
OnNotificationsReceived
notificationProfile(Optional) The name of the notification profile (sound, icon and other notification attributes).
badgeNumber(Optional) The badge number, to be displayed on top of application icon, when supported. Use Notification.BADGE_NOT_SPECIFIED (default) to keep previous value, 0 to hide the badge.
buttons(Optional) A collection of custom buttons (Android only, ignored on the rest platforms).

Please note that the actual interval may be different. On iOS there are only fixed options like every minute, every day, every week and so on. So the provided intervalSeconds value will be approximated by one of the available options.

◆ SetBadge()

abstract void UTNotifications.Manager.SetBadge ( int  bandgeNumber)
pure virtual

Sets the app icon badge value when supported.

◆ SetNotificationsEnabled()

abstract void UTNotifications.Manager.SetNotificationsEnabled ( bool  enabled)
pure virtual

Enables or disables showing any notifications (doesn't affect the OS settings).

Please note that enabling may change the registrationId so OnSendRegistrationId event will be called.

See also
OnSendRegistrationId

◆ SetPushNotificationsEnabled()

abstract bool UTNotifications.Manager.SetPushNotificationsEnabled ( bool  enable)
pure virtual

Enables push notifications, if any are configured and supported on the given platform (doesn't affect the OS settings).

Returns
true, if push notifications were enabled, false otherwise.

When disabled invalidates the old registration id. Please note that OnSendRegistrationId event will be called if enabled providing a new registrationId.

See also
OnSendRegistrationId

◆ SubscribeToTopic()

abstract void UTNotifications.Manager.SubscribeToTopic ( string  topic)
pure virtual

Subscribes to an FCM topic.

Android/Firebase Cloud Messaging only. Ignored on any other platform.

◆ UnsubscribeFromTopic()

abstract void UTNotifications.Manager.UnsubscribeFromTopic ( string  topic)
pure virtual

Unsubscribes from an FCM topic.

Android/Firebase Cloud Messaging only. Ignored on any other platform.

Property Documentation

◆ Initialized

bool UTNotifications.Manager.Initialized
getprotected set

true if the Manager is initialized.

◆ Instance

Manager UTNotifications.Manager.Instance
staticget

This is how you access the one and only instance of the Manager.

◆ ScheduledNotifications

ICollection<ScheduledNotification> UTNotifications.Manager.ScheduledNotifications
get

Returns a collection of all currently scheduled local notifications, including one-time and repeating notifications. One-time notifications that have already been shown are not included.

In some cases notifications can be displayed by the target OS some time later than it was scheduled. In that case, the returned collection can be missing those notifications, though they in fact haven't been shown yet.

Event Documentation

◆ OnInitialized

OnInitializedHandler UTNotifications.Manager.OnInitialized

Occurs when the Manager get initialized.

◆ OnNotificationClicked

OnNotificationClickedHandler UTNotifications.Manager.OnNotificationClicked

Occurs when a user tapped/clicked on a notification or its button.

Parameters
notificationClicked notification.
See also
UTNotifications.ReceivedNotification

Please subscribe to the event prior to calling Initialize to be able to handle a click on the notification which started the app.

◆ OnNotificationsReceived

OnNotificationsReceivedHandler UTNotifications.Manager.OnNotificationsReceived

Occurs when one or more local, scheduled or push notifications are received.

Parameters
receivedNotificationsA list of received ReceivedNotifications.
See also
UTNotifications.ReceivedNotification

iOS doesn't provide a list of all notifications shown when an app wasn't running in foreground. This list will contain only a notification, which was clicked and all notifications shown when an app is running in foreground. On the rest platforms you'll receive a list of all the shown notifications.

◆ OnPushRegistrationFailed

OnPushRegistrationFailedHandler UTNotifications.Manager.OnPushRegistrationFailed

Occurs if registering for push notifications is failed.

Parameters
errorError message.

◆ OnSendRegistrationId

OnSendRegistrationIdHandler UTNotifications.Manager.OnSendRegistrationId

Occurs when the registrationId for push notifications is received and should be sent to your server.

Parameters
providerNameA name of a push notifications provider. May be "APNS", "FCM", "ADM" or "WNS".
registrationIdThe received registrationId (encoded on iOS - see remarks).

The documentation for this class was generated from the following file: