Customize Notifications

Configure notification options, foreground presentation, badges, and Android notification defaults.

View as Markdown

iOS Notification Options

iOS-specific push settings are available through Airship.Shared.push.iOS. These calls are no-ops on Android.

By default, the Airship SDK requests Alert, Badge, and Sound notification options for remote notifications. Configure the options before enabling user notifications.

Airship.Shared.push.iOS.SetNotificationOptions(new NotificationOption[] {
    NotificationOption.Alert,
    NotificationOption.Sound,
    NotificationOption.Badge,
});

Provisional Authorization

Apps can request provisional authorization along with the usual notification options. With provisional authorization, apps do not need to prompt the user for permission initially, and notifications are delivered quietly to the Notification Center until the user explicitly chooses to keep receiving them.

Airship.Shared.push.iOS.SetNotificationOptions(new NotificationOption[] {
    NotificationOption.Alert,
    NotificationOption.Sound,
    NotificationOption.Badge,
    NotificationOption.Provisional,
});

Foreground Presentation Options

Control how a notification is displayed when it is received while the app is in the foreground.

Airship.Shared.push.iOS.SetForegroundPresentationOptions(new ForegroundPresentationOption[] {
    ForegroundPresentationOption.Sound,
    ForegroundPresentationOption.Badge,
    ForegroundPresentationOption.List,
    ForegroundPresentationOption.Banner
});

Badges

The badge on iOS presents a counter on top of the application icon. Setting the badge is asynchronous, so run it as a coroutine.

// Enable auto-badge
Airship.Shared.push.iOS.SetAutobadgeEnabled(true);

// Set the badge number
StartCoroutine(Airship.Shared.push.iOS.SetBadgeNumber(1));

// Reset badge
StartCoroutine(Airship.Shared.push.iOS.SetBadgeNumber(0));
Important

When using auto-badge, only modify the badge value through Airship methods to ensure the value stays in sync.

Quiet Time

Quiet time suppresses notification sounds and vibrations during a scheduled time window.

Airship.Shared.push.iOS.SetQuietTimeEnabled(true);
Airship.Shared.push.iOS.SetQuietTime(new QuietTime() {
    startHour = 22,
    startMinute = 0,
    endHour = 7,
    endMinute = 0,
});

Android Notification Configuration

Configure the default notification appearance on Android through Airship.Shared.push.android. These calls are no-ops on iOS.

Airship.Shared.push.android.SetNotificationConfig(new AndroidNotificationConfig() {
    icon = "custom_notification_icon",
    accentColor = "#FF0000FF",
    defaultChannelId = "custom_channel",
});

Foreground Display Control

By default, push notifications received while the app is in the foreground on Android are displayed to the user. Control this behavior with SetForegroundNotificationsEnabled.

Airship.Shared.push.android.SetForegroundNotificationsEnabled(false);