Scheduling Notifications

Local notifications give you a way to alert the user at times when your app might not be running. You schedule local notifications at the time when your app is running either in the foreground or background. After scheduling a notification, the system takes on the responsibility of delivering the notification to the user at the appropriate time. Your app does not need to be running for the system to deliver the notification. If your app is not running, or if it is in the background, the system displays local notifications directly to the user. The system can alert the user with an alert panel or banner, with a sound, or by badging your app’s icon. If your app provides a notification content app extension, the system can even use your custom interface to alert the user. If your app is in the foreground when a notification arrives, the system gives your app the opportunity to handle the notification internally.

Request Authorization

Make sure you request Authorization before scheduling a notification. 

using UnityEngine;
using SA.CrossPlatform.Notifications;
...

var client = UM_NotificationCenter.Client;
client.RequestAuthorization((result) =>
{
    if (result.IsSucceeded)
    {
        Debug.Log("Authorization granted");
    }
    else
    {
        Debug.Log("User declined: " + result.Error.FullMessage);
    }
});

Configuring a Local Notification

The steps for configuring a local notification are as follows:

  1. Create and configure an UM_Notification object with the notification details.
  2. Create an UM_TimeIntervalNotificationTrigger object to describe the conditions under which the notification is delivered.
  3. Create an UM_NotificationRequest object with the content and trigger information.
  4. Call the UM_NotificationCenter.Client.AddNotificationRequest method to schedule the notification.

See the code example below:

using SA.CrossPlatform.Notifications;
...

var client = UM_NotificationCenter.Client;
var content = new UM_Notification();

content.SetTitle("Title");
content.SetBody("Body message");
content.SetSmallIconName("myIcon.png");
content.SetSoundName("mySound.wav");

//Get unique request id, if notification will be posted with the same request id old one will be replaced with the new one
int requestId = 1; 
//2 seconds
var trigger = new UM_TimeIntervalNotificationTrigger(2);
var request = new UM_NotificationRequest(requestId, content, trigger);
client.AddNotificationRequest(request, (result) => {
    if(result.IsSucceeded) {
        //Notification was successfully scheduled
    } else {
        //There was an issue with scheduling
        Debug.Log(result.Error.FullMessage);
    }
});

Customize 

From the previous example, you probably notice that you may provide sound and icons to the local notification. But before you can do this, make sure you've configured sounds and icon for each platform you are going to use. See the customization guide for supported platform below: