Push Notifications for the Unity Plugin

How to configure your application to receive and respond to notifications.

Before you can send and receive push notifications, you need to configure your app for the platform(s) you’re targeting.

Platform Setup

Follow the platform-specific setup instructions below to enable push notifications in your Unity app.

iOS

After generating a project for iOS, enable Push Notifications in the project editor’s Capabilities pane:

Notification Service Extension

To take advantage of notification attachments, such as images, animated gifs, and video, you will need to create a notification service extension.

Follow the steps in the iOS Notification Service Extension Guide.

Android

Download the Android Firebase configuration file, google-services.json, from the application’s Firebase console and add it to the Assets directory.

If your Unity application does not have an associated application in the Firebase console, follow the FCM setup instructions to set one up.

Enable User Notifications

Enabling userNotificationsEnabled will prompt the user for permission to send notifications. To increase the likelihood that the user will accept, you should avoid prompting the user for permission immediately, and instead wait for a more appropriate time in the app.

The Airship SDK makes a distinction between user notifications, which can be seen by the user, and other forms of push that allow you to send data to your app silently, or in the background. Enabling or disabling user notifications is a preference often best left up to the user, so by default, user notifications are disabled.

UAirship.Shared.UserNotificationsEnabled = true;
 Note

For apps that target Android 13 (API 33) and above, enabling user notifications will display a runtime permission prompt to allow notifications to be sent.

To increase the likelihood that the user will accept, you should avoid prompting the user for permission immediately on app startup, and instead wait for a more appropriate time to prompt for notification permission.

Handle Notification Events

The Airship SDK provides several callbacks for when a push is received or a notification is interacted with. Apps can use these callbacks to do custom push processing. Registering for a callback is optional, the SDK will automatically launch the application without the need to set a callback.

UAirship.Shared.OnPushReceived += (PushMessage message) => {
  // Handle message
};

UAirship.Shared.OnPushOpened += (PushMessage message) => {
  // Handle message
};

Silent Notifications

Silent notifications are push messages that do not present a notification to the user. These are typically used to briefly wake the app from a background state to perform processing tasks or fetch remote content.

 Important

We recommend that you thoroughly test your implementation to confirm that silent notifications do not generate any device notifications.

For Android, all push messages are delivered in the background, but default Airship will treat messages without an alert as silent. For iOS, set the content_available property to true in the iOS override object.

 Note

Pushes sent with the content_available property (iOS) or without an alert (Android) do not have guaranteed delivery. Factors affecting delivery include battery life, whether the device is connected to WiFi, and the number of silent pushes sent within a recent time period. These metrics are determined solely by iOS/Android and APNs/FCM. Therefore, this feature is best used for supplementing the regular behavior of the app rather than providing critical functionality. For instance, an app could use a silent push to pre-fetch new data ahead of time in order to reduce load times when the app is later launched by the user.

iOS Notification Options

 Note

iOS notification options, badges, and quiet time are not supported in Unity.