Usage

Once after the setup, import the namespace to access the features from Notification Services.

using VoxelBusters.CoreLibrary;
using VoxelBusters.EssentialKit;

Request Access (for presentation options)

A notification can have a visual display, sound, badge and other properties. You need to request them based on how you want to present the notifications to the user with RequestPermission method.

NotificationServices.RequestPermission(NotificationPermissionOptions.Alert | NotificationPermissionOptions.Sound | NotificationPermissionOptions.Badge, callback: (result, error) =>
{
    Debug.Log("Request for access finished.");
    Debug.Log("Notification access status: " + result.PermissionStatus);
});

Get Settings

You can check what settings user allowed with GetSettings method. This will be handy if you want to check if user denied the settings so that you can prompt him with suitable message.

NotificationServices.GetSettings((result) =>
{
    NotificationSettings settings    = result.Settings;
    // update console
    Debug.Log(settings.ToString());

    Debug.Log("Permission status : " + settings.PermissionStatus);
});

Local Notifications

Create a Notification Message

For scheduling notifications, you need to create an instance of INotification.

Schedule Notification

For scheduling a notification, you need to have an instance of INotification which contains the details required for a notification. Use ScheduleNotification for scheduling the notification.

The above call will schedule the notification instantly and incase if you want to schedule in the future, you need to set the Time Interval Trigger

Repeat Notifications

When setting the time interval notification you can pass additionally repeat status to repeat the notification. The below notification repeats every 10 seconds.

Get Scheduled Notifications

You can get the list of all scheduled notifications and not yet delivered with GetScheduledNotifications

Cancel Scheduled Notification/Notifications

As each notification has an unique Id (assigned when creating), you can cancel the notification with this id.

Cancel all scheduled notifications

Get Delivered Notifications

GetDeliveredNotifications return all the notifications delivered in the Android or iOS notification center.

Remove Delivered Notifications

RemoveAllDeliveredNotifications removes all notifications delivered in the Android or iOS notification center .

Push Notifications or Remote Notifications

While local notifications are created locally and delivered to the device, Push notifications needs an external/backend server to deliver the notification to device.

Go through the following steps to understand how a push notification works.

  1. Device registers for push notifications and receive a token

  2. The token(also known as device token or registration token) will be sent to your backend server

  3. Your backend server constructs the message payload it wants to pass to your device and sends a request to the platform's notification servers (APNS on iOS and FCM on Android) along with the device token it received in step 2.

  4. Platform's notification servers then targets the device with the device token and pushes the message payload to the device.

  5. Yay! 👯‍♂️ Your device will receive a notification!

Remote Notifications Management

For getting the device token, you first need to register for push notifications. In the callback, you get the device token.

Also, you can check if remote notifications are already registered on the device with IsRegisteredForRemoteNotifications

Once you are done with the remote notifications, you can unregister for the push notifications.

Detecting App launch through Notification

There will be cases where you need to identify if the app is launched when user clicked on the notification from Notification Center.

INotification has a property IsLaunchNotification property which tells if the notification is launched on user tap.

Plugin automatically delays delivering the notification until you register for NotificationServices.OnNotificationReceived event. Once you register, plugin delivers with IsLaunchNotification variable set to true if it's tapped by the user.

Last updated

Was this helpful?