expo-notifications
Version:
Provides an API to fetch push notification tokens and to present, schedule, receive, and respond to notifications.
33 lines (28 loc) • 1.48 kB
text/typescript
import { UnavailabilityError, Platform } from 'expo-modules-core';
import BadgeModule from './BadgeModule';
import { WebSetBadgeCountOptions } from './BadgeModule.types';
export interface SetBadgeCountOptions {
/**
* A configuration object described [in the `badgin` documentation](https://github.com/jaulz/badgin#options).
*/
web?: WebSetBadgeCountOptions;
}
/**
* Sets the badge of the app's icon to the specified number. Setting it to `0` clears the badge. On iOS, this method requires that you have requested
* the user's permission for `allowBadge` via [`requestPermissionsAsync`](#requestpermissionsasyncpermissions),
* otherwise it will automatically return `false`.
* > **Note:** Not all Android launchers support application badges. If the launcher does not support icon badges, the method will resolve to `false`.
* @param badgeCount The count which should appear on the badge. A value of `0` will clear the badge.
* @param options An object of options configuring behavior applied.
* @return It returns a Promise resolving to a boolean representing whether the setting of the badge succeeded.
* @header badge
*/
export default async function setBadgeCountAsync(
badgeCount: number,
options?: SetBadgeCountOptions
): Promise<boolean> {
if (!BadgeModule.setBadgeCountAsync) {
throw new UnavailabilityError('ExpoNotifications', 'setBadgeCountAsync');
}
return await BadgeModule.setBadgeCountAsync(badgeCount, options?.[Platform.OS]);
}