Usage

Schedule local notifications and implement push notifications for player engagement

Essential Kit wraps native iOS (Apple Push Notification service, or APNs) and Android (Firebase Cloud Messaging, or FCM) notification APIs into a single Unity interface. Essential Kit auto-initializes NotificationServices - you can start scheduling notifications immediately after requesting permissions.

Table of Contents

Understanding Core Concepts

Before scheduling notifications, understand the two distinct notification types and when to use each.

Local vs Push Notifications

Local Notifications are scheduled on the device and fire even when your app isn't running. Perfect for game-driven events.

Examples:

  • Energy refill timers (30 minutes after energy depletes)

  • Daily reward reminders (every day at 6 PM)

  • Building completion timers (when construction finishes)

  • Recurring challenges (weekly tournament reminders)

Key characteristics:

  • Work completely offline - no server required

  • Scheduled using time intervals or calendar dates

  • Stored on device until fired or cancelled

  • Limited to device-scheduled triggers only

Push Notifications are sent from your game server to devices in real-time. Perfect for server-driven events.

Examples:

  • Tournament results and leaderboard updates

  • Flash sale announcements

  • Friend requests and social interactions

  • Server maintenance notices

Key characteristics:

  • Require server infrastructure (Firebase, OneSignal, or custom backend)

  • Can target specific users or broadcast to all players

  • Sent in real-time based on server events

  • Can carry custom data for deep linking

Rule of thumb: Use local notifications for predictable game events, push notifications for dynamic server events and social features.

Notification Triggers

Local notifications fire based on triggers you specify when scheduling:

Time Interval Triggers fire after a specific delay from scheduling. Use for relative timing like cooldowns and energy refills.

Calendar Triggers fire at specific clock times. Use for daily rewards, weekly events, and scheduled content.

Notification Lifecycle

  1. Creation: Build notification with NotificationBuilder specifying ID, title, body, and trigger

  2. Scheduling: Call ScheduleNotification() to register with system

  3. Delivery: System fires notification at trigger time (or immediately for push notifications)

  4. User Interaction: User taps notification to open app, or dismisses it

  5. Handling: Your app receives OnNotificationReceived event with notification data

Import Namespaces

Include System namespaces for DateTime and Dictionary which are commonly used with notification scheduling and custom data.

Event Registration

Register for notification events in OnEnable and unregister in OnDisable to receive notifications and permission updates:

Event
Trigger

OnNotificationReceived

When local or push notification is delivered (foreground or background), or when user taps notification to open app

OnSettingsUpdate

When user changes notification permissions in device settings

How Permissions Work

Just call RequestPermission() directly - no permission checks needed beforehand. On the first call, Essential Kit automatically shows the system permission dialog. If permission is already granted, it completes immediately. When the user denies access, result.PermissionStatus becomes Denied while the error argument stays null.

Handling Permission Denial

Handle permission issues in the error callback or by checking the permission status:

Optional: Check Permission Status

Use GetSettings() only when you need to inspect the exact state before calling the main operation, or to customize UI messaging:

Permission status values:

  • NotDetermined: Permission never requested (iOS) or not applicable (Android)

  • Denied: User explicitly denied permission

  • Authorized: User granted full notification permissions

  • Provisional: Limited permissions granted (iOS 12+ quiet notifications)

Local Notifications

Creating Notifications

Build notifications using NotificationBuilder with a unique ID, title, body, and trigger:

Scheduling Notifications

Schedule the notification to be delivered at the trigger time:

Notification Triggers

Time Interval Triggers

Use when timing is relative to the current moment:

Common patterns:

  • Energy refills: 30-60 minutes after depletion

  • Lives regeneration: Time until next life available

  • Building timers: Construction completion time

  • Temporary boosts: When boost expires

Calendar Triggers

Use when timing should match specific clock times:

Common patterns:

Calendar trigger rule: The most specific component determines repeat frequency. Hour only → repeats hourly; Hour + Minute → repeats daily; Day + Hour + Minute → repeats monthly; Month + Day + Hour + Minute → repeats annually.

Adding Custom Data

Attach custom data to notifications for deep linking or identifying notification types:

Access custom data in your event handler:

Managing Scheduled Notifications

Get Scheduled Notifications

Retrieve all pending notifications that haven't been delivered yet:

Cancel Scheduled Notifications

Common patterns:

Delivered Notifications

Get Delivered Notifications

Retrieve notifications currently visible in the device notification center:

Clear Delivered Notifications

Push Notifications

Push notifications require server infrastructure to send messages. Essential Kit handles device registration and notification reception.

Understanding Push Notification Flow

  1. Device registration: Your app requests a push notification device token.

  2. Token storage: Send the token to your game server (Essential Kit also caches it locally).

  3. Server send: Your server forwards the payload to APNs (iOS) or FCM (Android).

  4. Platform delivery: Apple or Google push gateways route the message to the device.

  5. App receives: Essential Kit surfaces the payload via OnNotificationReceived.

Registering for Push Notifications

Request device token after user grants notification permissions:

Essential Kit also provides helpers when you want the plugin to manage re-registration or expose a global callback:

Platform-Specific Token Formats

  • iOS: Returns APNS device token (send to your APNS server or convert to FCM token)

  • Android: Returns FCM registration token (send directly to FCM)

For unified backends, use FCM SDK to convert APNS tokens to FCM tokens on iOS, allowing a single FCM endpoint for both platforms.

Checking Registration Status

Unregistering from Push Notifications

Unregistering from push notifications can save battery when user disables notifications in your game settings. You can always re-register later.

Handling Push Notification Reception

Push notifications are delivered through the same OnNotificationReceived event as local notifications:

Server Payload Examples

Reference payloads for testing push notifications from your server:

Android (FCM) Payload:

iOS (APNS) Payload:

Badge Management

Update the badge number on your app icon to show notification counts or pending items:

Common patterns:

Data Properties

Item
Type
Notes

NotificationServicesNotificationReceivedResult.Notification

INotification

Gives you the fully-populated notification instance (title, body, payload, trigger) whenever OnNotificationReceived fires.

INotification.UserInfo

IDictionary

Custom key/value payload from local builders or remote push messages—use it for deep links and contextual routing.

INotification.IsLaunchNotification

bool

Identifies whether the notification launched or re-activated the app so you can branch onboarding flows.

NotificationSettings.PermissionStatus

NotificationPermissionStatus

Reflects the latest permission choice (Authorized, Denied, etc.) returned by GetSettings and cached on NotificationServices.CachedSettings.

NotificationSettings.DeviceToken

string

The most recent device token (APNs/FCM). Send it to your backend whenever you register for push notifications.

NotificationSettings.PushNotificationEnabled

bool

Confirms whether the platform currently allows remote notifications—handy before prompting users to re-enable permissions.

Core APIs Reference

API
Purpose
Returns

NotificationServices.RequestPermission(options, callback)

Request notification permissions (Alert, Sound, Badge)

Result via callback with PermissionStatus or error

NotificationBuilder.CreateNotification(id)

Start building a notification with unique identifier

NotificationBuilder instance for method chaining

NotificationServices.ScheduleNotification(notification, callback)

Schedule local notification for delivery

Success flag via callback

NotificationServices.GetScheduledNotifications(callback)

Get all pending scheduled notifications

Array of INotification via callback

NotificationServices.CancelScheduledNotification(id)

Cancel specific scheduled notification by ID

No return value

NotificationServices.CancelAllScheduledNotifications()

Cancel all pending scheduled notifications

No return value

NotificationServices.GetDeliveredNotifications(callback)

Get notifications currently in notification center

Array of INotification via callback

NotificationServices.RemoveAllDeliveredNotifications()

Clear all notifications from notification center

No return value

NotificationServices.RegisterForPushNotifications(callback)

Register device for push notifications

Device token via callback

NotificationServices.UnregisterForPushNotifications()

Unregister from push notifications

No return value

NotificationServices.IsRegisteredForPushNotifications()

Check if device is registered for push

bool - true if registered

NotificationServices.SetApplicationIconBadgeNumber(count)

Set app icon badge number (0 to clear)

No return value

NotificationServices.GetSettings(callback)

Optional: Get current permission status and settings

NotificationSettings via callback

NotificationServices.CachedSettings

Access cached notification settings without callback

NotificationSettings object

NotificationBuilder Methods

Chain these methods when building notifications:

Method
Purpose

SetTitle(title)

Set notification title text

SetSubtitle(subtitle)

Set notification subtitle (iOS only)

SetBody(body)

Set notification body message

SetBadge(number)

Set app icon badge number

SetUserInfo(dictionary)

Set custom data dictionary

SetPriority(priority)

Set notification priority (Low/Medium/High/Max)

SetTimeIntervalNotificationTrigger(seconds, repeats)

Set time-based trigger (seconds from now)

SetCalendarNotificationTrigger(components, repeats)

Set calendar-based trigger (specific times/dates)

SetSoundFileName(filename)

Set custom sound file from StreamingAssets

SetAndroidProperties(properties)

Set Android-specific properties (channels, icons)

SetIosProperties(properties)

Set iOS-specific properties (thread ID, attachments)

Create()

Build and return final INotification object

Error Handling

Error Code
Trigger
Recommended Action

PermissionNotAvailable

User declined notification permissions

Show explanation of benefits and guide to Utilities.OpenApplicationSettings()

TriggerNotValid

Missing or incompatible trigger configuration

Ensure the trigger type matches the platform requirements

ConfigurationError

Notification payload missing required data

Ensure title/body/payload are populated before scheduling

ScheduledTimeNotValid

Scheduled time already elapsed or invalid

Validate the fire time before submitting the request

Unknown

Platform-specific error occurred

Log error details and retry or contact support

Error handling pattern:

Advanced: Manual Initialization

Understanding Auto-Initialization

Default behavior (no action required):

  • Essential Kit automatically initializes NotificationServices before scene loads

  • Uses settings from Resources/EssentialKitSettings.asset

  • Notification system is immediately ready for use

  • Suitable for 99% of use cases

Advanced manual initialization: Override default settings at runtime for specific scenarios:

When to use manual initialization:

  • Feature flag systems controlling notification availability

  • Server-driven configuration for presentation options

  • Environment-specific push service types (dev/staging/production)

  • Runtime permission option configuration based on user preferences

When NOT to use manual initialization:

  • Standard notification implementation

  • Default presentation options work for your game

  • Using settings configured in Essential Kit Settings

  • No runtime configuration changes needed

  • Demo scene: Assets/Plugins/VoxelBusters/EssentialKit/Examples/Scenes/NotificationServicesDemo.unity

  • Use Utilities.OpenApplicationSettings() for permission recovery flows when users deny notifications

  • Pair with DeepLinkServices to handle notification taps that should navigate to specific in-game content

  • Combine with CloudServices to sync notification preferences across devices

Last updated

Was this helpful?