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
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
Creation: Build notification with NotificationBuilder specifying ID, title, body, and trigger
Scheduling: Call
ScheduleNotification()to register with systemDelivery: System fires notification at trigger time (or immediately for push notifications)
User Interaction: User taps notification to open app, or dismisses it
Handling: Your app receives
OnNotificationReceivedevent 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:
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
Essential Kit automatically delays delivering launch notifications until you register for OnNotificationReceived. This prevents missing notifications that arrived before your code was ready to handle them.
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.
UX best practice: Show a custom explanation screen before requesting permissions. Explain benefits like "Get notified when your energy refills" to improve approval rates. iOS users especially appreciate understanding value before seeing system dialogs.
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 permissionAuthorized: User granted full notification permissionsProvisional: Limited permissions granted (iOS 12+ quiet notifications)
Local Notifications
Creating Notifications
Build notifications using NotificationBuilder with a unique ID, title, body, and trigger:
Notification IDs must be unique. Scheduling a notification with an existing ID replaces the previous notification. Use descriptive IDs like "energy_refill" or "daily_reward" for easier management.
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:
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
Device registration: Your app requests a push notification device token.
Token storage: Send the token to your game server (Essential Kit also caches it locally).
Server send: Your server forwards the payload to APNs (iOS) or FCM (Android).
Platform delivery: Apple or Google push gateways route the message to the device.
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:
Device token caching: Essential Kit caches the device token after successful registration. Access it anytime with NotificationServices.CachedSettings.DeviceToken without making another registration request.
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
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:
Badge numbers require Badge permission in RequestPermission(). On iOS, badge may not be visible if user disabled badges in device settings. Badge permission is granted independently of alert/sound permissions.
Data Properties
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
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:
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
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
Advanced users only: Essential Kit auto-initializes NotificationServices with settings from Essential Kit Settings. Only use manual initialization for runtime configuration changes, feature flags, or server-driven settings.
Understanding Auto-Initialization
Default behavior (no action required):
Essential Kit automatically initializes NotificationServices before scene loads
Uses settings from
Resources/EssentialKitSettings.assetNotification 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
Calling Initialize() resets all event listeners. Re-register for OnNotificationReceived and other events after initialization.
Related Guides
Demo scene:
Assets/Plugins/VoxelBusters/EssentialKit/Examples/Scenes/NotificationServicesDemo.unityUse 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
Ready to test? Head to Testing to validate your notification implementation.
Last updated
Was this helpful?