Cross Platform Native Plugins
A true cross platform tool for Unity which provides unique and unified way to access native functionality on mobile platforms.
Public Member Functions | Events | List of all members
NotificationService Class Reference

Provides cross-platform interface for scheduling, registering and handling notifications. More...

Public Member Functions

virtual void RegisterNotificationTypes (NotificationType _notificationTypes)
 Registers your preferred options for notifying the user. More...
 
virtual NotificationType EnabledNotificationTypes ()
 Returns the types of notifications currently enabled for the app. More...
 
virtual string ScheduleLocalNotification (CrossPlatformNotification _notification)
 Schedules a local notification for delivery at specified date and time. More...
 
virtual void CancelLocalNotification (string _notificationID)
 Cancels the delivery of the specified scheduled local notification. More...
 
virtual void CancelAllLocalNotification ()
 Cancels the delivery of all scheduled local notifications. More...
 
virtual void ClearNotifications ()
 Discards all the received notifications. More...
 
virtual void RegisterForRemoteNotifications ()
 Registers to receive remote notifications via Push Notification service. More...
 
virtual void UnregisterForRemoteNotifications ()
 Unregister for all remote notifications received via Push Notification service. More...
 
delegate void RegisterForRemoteNotificationCompletion (string _deviceToken, string _error)
 Delegate that will be called when your app completes registration with Push Notification service. More...
 
delegate void ReceivedNotificationResponse (CrossPlatformNotification _notification)
 Delegate that will be called when your app receives a notification. More...
 

Events

static RegisterForRemoteNotificationCompletion DidFinishRegisterForRemoteNotificationEvent
 Event that will be called when your app completes registration with Push Notification service. More...
 
static ReceivedNotificationResponse DidLaunchWithLocalNotificationEvent
 Event that will be called when your app was launched as a result of local notification. More...
 
static ReceivedNotificationResponse DidLaunchWithRemoteNotificationEvent
 Event that will be called when your app was launched as a result of remote notification. More...
 
static ReceivedNotificationResponse DidReceiveLocalNotificationEvent
 Event that will be called when your app has received a local notification. More...
 
static ReceivedNotificationResponse DidReceiveRemoteNotificationEvent
 Event that will be called when your app has received a remote notification. More...
 

Detailed Description

Provides cross-platform interface for scheduling, registering and handling notifications.

Member Function Documentation

virtual void RegisterNotificationTypes ( NotificationType  _notificationTypes)
virtual

Registers your preferred options for notifying the user.

If your app displays alerts, play sounds, or badges its icon, you must call this method soon after the app launch to request permission to alert the user in these ways.

Parameters
_notificationTypesThe notification types that your app uses to alert user.
Note
It is recommended that you call this method before you schedule any local notifications or register with the push notification service. Multiple types can be combined together using the | operator.
virtual NotificationType EnabledNotificationTypes ( )
virtual

Returns the types of notifications currently enabled for the app.

The values in the returned bit mask are first set when the app calls RegisterNotificationTypes method. Thereafter the user may modify these notification types from system preference.

Returns
The bit mask indicate the types of notifications currently enabled for the app.
virtual string ScheduleLocalNotification ( CrossPlatformNotification  _notification)
virtual

Schedules a local notification for delivery at specified date and time.

Returns
A string used to uniquely identify the scheduled notification.
Parameters
_notificationThe local notification object that you want to schedule.
Note
Prior to scheduling any local notifications, you must call the RegisterNotificationTypes method if you want system to display alerts, play sounds etc.
virtual void CancelLocalNotification ( string  _notificationID)
virtual

Cancels the delivery of the specified scheduled local notification.

Parameters
_notificationIDA string used to uniquely identify the notification.
virtual void CancelAllLocalNotification ( )
virtual

Cancels the delivery of all scheduled local notifications.

virtual void ClearNotifications ( )
virtual

Discards all the received notifications.

virtual void RegisterForRemoteNotifications ( )
virtual

Registers to receive remote notifications via Push Notification service.

Call this method to initiate the registration process with Push Notification service. When registration process completes, DidFinishRegisterForRemoteNotificationEvent is fired. If registration succeeds, then you should pass device token to the server you use to generate remote notifications.

Note
If you want your app’s remote notifications to display alerts, play sounds etc you must call the RegisterNotificationTypes method before registering for remote notifications.
virtual void UnregisterForRemoteNotifications ( )
virtual

Unregister for all remote notifications received via Push Notification service.

Note
Apps unregistered through this method can always re-register.
delegate void RegisterForRemoteNotificationCompletion ( string  _deviceToken,
string  _error 
)

Delegate that will be called when your app completes registration with Push Notification service.

Parameters
_deviceTokenA token that identifies the device to Push Notification service.
_errorIf the operation was successful, this value is nil; otherwise, this parameter holds the description of the problem that occurred.
delegate void ReceivedNotificationResponse ( CrossPlatformNotification  _notification)

Delegate that will be called when your app receives a notification.

Parameters
_notificationThe CrossPlatformNotification object holds information about received notification.

Event Documentation

RegisterForRemoteNotificationCompletion DidFinishRegisterForRemoteNotificationEvent
static

Event that will be called when your app completes registration with Push Notification service.

After you call the RegisterForRemoteNotifications method, the app calls this method when device registration completes successfully or when there is an error in the registration process. When registration completes successfully, connect with your push notification server and give the device token to it. Push notification server pushes notifications only to the device represented by the token.

The following code example demonstrates how to use registration event.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
NotificationService.DidFinishRegisterForRemoteNotificationEvent += OnFinishedRemoteNotificationRegistration;
}
private void OnDisable ()
{
// Unregistering event
NotificationService.DidFinishRegisterForRemoteNotificationEvent -= OnFinishedRemoteNotificationRegistration;
}
private void OnFinishedRemoteNotificationRegistration (string _deviceToken, string _error)
{
if (_error == null)
{
// Send device token to your server
}
else
{
// Something went wrong
}
}
}
ReceivedNotificationResponse DidLaunchWithLocalNotificationEvent
static

Event that will be called when your app was launched as a result of local notification.

The following code example demonstrates how to use launched with local notification event.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
NotificationService.DidLaunchWithLocalNotificationEvent += OnLaunchedWithLocalNotification;
}
private void OnDisable ()
{
// Unregistering event
NotificationService.DidLaunchWithLocalNotificationEvent -= OnLaunchedWithLocalNotification;
}
private void OnLaunchedWithLocalNotification (CrossPlatformNotification _notification)
{
// Handle received notification
}
}
ReceivedNotificationResponse DidLaunchWithRemoteNotificationEvent
static

Event that will be called when your app was launched as a result of remote notification.

The following code example demonstrates how to use launched with remote notification event.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
NotificationService.DidLaunchWithRemoteNotificationEvent += OnLaunchedWithRemoteNotification;
}
private void OnDisable ()
{
// Unregistering event
NotificationService.DidLaunchWithRemoteNotificationEvent -= OnLaunchedWithRemoteNotification;
}
private void OnLaunchedWithRemoteNotification (CrossPlatformNotification _notification)
{
// Handle received notification
}
}
ReceivedNotificationResponse DidReceiveLocalNotificationEvent
static

Event that will be called when your app has received a local notification.

Note
This notifies about the notification received when your app is running.

The following code example demonstrates how to use local notification received event.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
NotificationService.DidReceiveLocalNotificationEvent += OnReceivingLocalNotification;
}
private void OnDisable ()
{
// Unregistering event
NotificationService.DidReceiveLocalNotificationEvent -= OnReceivingLocalNotification;
}
private void OnReceivingLocalNotification (CrossPlatformNotification _notification)
{
// Handle received notification
}
}
ReceivedNotificationResponse DidReceiveRemoteNotificationEvent
static

Event that will be called when your app has received a remote notification.

Note
This notifies about the notification received when your app is running.

The following code example demonstrates how to use remote notification received event.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
private void OnEnable ()
{
// Registering for event
NotificationService.DidReceiveRemoteNotificationEvent += OnReceivingRemoteNotification;
}
private void OnDisable ()
{
// Unregistering event
NotificationService.DidReceiveRemoteNotificationEvent -= OnReceivingRemoteNotification;
}
private void OnReceivingRemoteNotification (CrossPlatformNotification _notification)
{
// Handle received notification
}
}