react-native-onesignal
Version:
React Native OneSignal SDK
328 lines (327 loc) • 18.3 kB
TypeScript
import { NotificationEventName, NotificationEventTypeMap, NotificationClickEvent } from './models/NotificationEvents';
import { PushSubscriptionState, OSNotificationPermission, PushSubscriptionChangedState } from './models/Subscription';
import { UserState, UserChangedState } from './models/User';
import NotificationWillDisplayEvent from './events/NotificationWillDisplayEvent';
import { LiveActivitySetupOptions } from './models/LiveActivities';
import { InAppMessage, InAppMessageEventTypeMap, InAppMessageEventName, InAppMessageClickEvent, InAppMessageWillDisplayEvent, InAppMessageDidDisplayEvent, InAppMessageWillDismissEvent, InAppMessageDidDismissEvent } from './models/InAppMessage';
export declare enum LogLevel {
None = 0,
Fatal = 1,
Error = 2,
Warn = 3,
Info = 4,
Debug = 5,
Verbose = 6
}
export declare namespace OneSignal {
/** Initializes the OneSignal SDK. This should be called during startup of the application. */
function initialize(appId: string): void;
/**
* If your integration is user-centric, or you want the ability to identify the user beyond the current device, the
* login method should be called to identify the user.
*/
function login(externalId: string): void;
/**
* Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the logout method should be
* called.
*/
function logout(): void;
/** For GDPR users, your application should call this method before setting the App ID. */
function setConsentRequired(required: boolean): void;
/**
* If your application is set to require the user's privacy consent, you can provide this consent using this method.
* Indicates whether privacy consent has been granted. This field is only relevant when the application has opted
* into data privacy protections.
*/
function setConsentGiven(granted: boolean): void;
namespace Debug {
/**
* Enable logging to help debug if you run into an issue setting up OneSignal.
* @param {LogLevel} nsLogLevel - Sets the logging level to print to the Android LogCat log or Xcode log.
*/
function setLogLevel(nsLogLevel: LogLevel): void;
/**
* Enable logging to help debug if you run into an issue setting up OneSignal.
* @param {LogLevel} visualLogLevel - Sets the logging level to show as alert dialogs.
*/
function setAlertLevel(visualLogLevel: LogLevel): void;
}
namespace LiveActivities {
/**
* Indicate this device has exited a live activity, identified within OneSignal by the `activityId`.
*
* Only applies to iOS
*
* @param activityId: The activity identifier the live activity on this device will receive updates for.
* @param token: The activity's update token to receive the updates.
**/
function enter(activityId: string, token: string, handler?: Function): void;
/**
* Indicate this device has exited a live activity, identified within OneSignal by the `activityId`.
*
* Only applies to iOS
*
* @param activityId: The activity identifier the live activity on this device will no longer receive updates for.
**/
function exit(activityId: string, handler?: Function): void;
/**
* Indicate this device is capable of receiving pushToStart live activities for the
* `activityType`. The `activityType` **must** be the name of the struct conforming
* to `ActivityAttributes` that will be used to start the live activity.
*
* Only applies to iOS
*
* @param activityType: The name of the specific `ActivityAttributes` structure tied
* to the live activity.
* @param token: The activity type's pushToStart token.
*/
function setPushToStartToken(activityType: string, token: string): void;
/**
* Indicate this device is no longer capable of receiving pushToStart live activities
* for the `activityType`. The `activityType` **must** be the name of the struct conforming
* to `ActivityAttributes` that will be used to start the live activity.
*
* Only applies to iOS
*
* @param activityType: The name of the specific `ActivityAttributes` structure tied
* to the live activity.
*/
function removePushToStartToken(activityType: string): void;
/**
* Enable the OneSignalSDK to setup the default`DefaultLiveActivityAttributes` structure,
* which conforms to the `OneSignalLiveActivityAttributes`. When using this function, the
* widget attributes are owned by the OneSignal SDK, which will allow the SDK to handle the
* entire lifecycle of the live activity. All that is needed from an app-perspective is to
* create a Live Activity widget in a widget extension, with a `ActivityConfiguration` for
* `DefaultLiveActivityAttributes`. This is most useful for users that (1) only have one Live
* Activity widget and (2) are using a cross-platform framework and do not want to create the
* cross-platform <-> iOS native bindings to manage ActivityKit.
*
* Only applies to iOS
*
* @param options: An optional structure to provide for more granular setup options.
*/
function setupDefault(options?: LiveActivitySetupOptions): void;
/**
* Start a new LiveActivity that is modelled by the default`DefaultLiveActivityAttributes`
* structure. The `DefaultLiveActivityAttributes` is initialized with the dynamic `attributes`
* and `content` passed in.
*
* Only applies to iOS
*
* @param activityId: The activity identifier the live activity on this device will be started
* and eligible to receive updates for.
* @param attributes: A dynamic type containing the static attributes passed into `DefaultLiveActivityAttributes`.
* @param content: A dynamic type containing the content attributes passed into `DefaultLiveActivityAttributes`.
*/
function startDefault(activityId: string, attributes: object, content: object): void;
}
namespace User {
namespace pushSubscription {
/** Add a callback that fires when the OneSignal subscription state changes. */
function addEventListener(event: 'change', listener: (event: PushSubscriptionChangedState) => void): void;
/** Clears current subscription observers. */
function removeEventListener(event: 'change', listener: (event: PushSubscriptionChangedState) => void): void;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getIdAsync}.
*/
function getPushSubscriptionId(): string;
function getIdAsync(): Promise<string | null>;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getTokenAsync}.
*/
function getPushSubscriptionToken(): string;
/** The readonly push subscription token */
function getTokenAsync(): Promise<string | null>;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getOptedInAsync}.
*/
function getOptedIn(): boolean;
/**
* Gets a boolean value indicating whether the current user is opted in to push notifications.
* This returns true when the app has notifications permission and optOut is not called.
* Note: Does not take into account the existence of the subscription ID and push token.
* This boolean may return true but push notifications may still not be received by the user.
*/
function getOptedInAsync(): Promise<boolean>;
/** Disable the push notification subscription to OneSignal. */
function optOut(): void;
/** Enable the push notification subscription to OneSignal. */
function optIn(): void;
}
/**
* Add a callback that fires when the OneSignal user state changes.
* Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
*/
function addEventListener(event: 'change', listener: (event: UserChangedState) => void): void;
/** Clears current user state observers. */
function removeEventListener(event: 'change', listener: (event: UserChangedState) => void): void;
/** Get the nullable OneSignal Id associated with the user. */
function getOnesignalId(): Promise<string | null>;
/** Get the nullable External Id associated with the user. */
function getExternalId(): Promise<string | null>;
/** Explicitly set a 2-character language code for the user. */
function setLanguage(language: string): void;
/** Set an alias for the current user. If this alias label already exists on this user, it will be overwritten with the new alias id. */
function addAlias(label: string, id: string): void;
/** Set aliases for the current user. If any alias already exists, it will be overwritten to the new values. */
function addAliases(aliases: object): void;
/** Remove an alias from the current user. */
function removeAlias(label: string): void;
/** Remove aliases from the current user. */
function removeAliases(labels: string[]): void;
/** Add a new email subscription to the current user. */
function addEmail(email: string): void;
/**
* Remove an email subscription from the current user. Returns false if the specified email does not exist on the user within the SDK,
* and no request will be made.
*/
function removeEmail(email: string): void;
/** Add a new SMS subscription to the current user. */
function addSms(smsNumber: string): void;
/**
* Remove an SMS subscription from the current user. Returns false if the specified SMS number does not exist on the user within the SDK,
* and no request will be made.
*/
function removeSms(smsNumber: string): void;
/**
* Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing
* messages. If the tag key already exists, it will be replaced with the value provided here.
*/
function addTag(key: string, value: string): void;
/**
* Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting
* specific users and/or personalizing messages. If the tag key already exists, it will be replaced with
* the value provided here.
*/
function addTags(tags: object): void;
/** Remove the data tag with the provided key from the current user. */
function removeTag(key: string): void;
/** Remove multiple tags with the provided keys from the current user. */
function removeTags(keys: string[]): void;
/** Returns the local tags for the current user. */
function getTags(): Promise<{
[key: string]: string;
}>;
}
namespace Notifications {
/**
* @deprecated This method is deprecated. It has been replaced by {@link getPermissionAsync}.
*/
function hasPermission(): boolean;
/**
* Whether this app has push notification permission. Returns true if the user has accepted permissions,
* or if the app has ephemeral or provisional permission.
*/
function getPermissionAsync(): Promise<boolean>;
/**
* Prompt the user for permission to receive push notifications. This will display the native system prompt to request push
* notification permission. Use the fallbackToSettings parameter to prompt to open the settings app if a user has already
* declined push permissions.
*/
function requestPermission(fallbackToSettings: boolean): Promise<boolean>;
/**
* Whether attempting to request notification permission will show a prompt. Returns true if the device has not been prompted for push
* notification permission already.
*/
function canRequestPermission(): Promise<boolean>;
/**
* Instead of having to prompt the user for permission to send them push notifications, your app can request provisional authorization.
* For more information: https://documentation.onesignal.com/docs/ios-customizations#provisional-push-notifications
* @param {(response:{accepted:boolean})=>void} handler
*/
function registerForProvisionalAuthorization(handler: (response: boolean) => void): void;
/** iOS Only.
* Returns the enum for the native permission of the device. It will be one of:
* OSNotificationPermissionNotDetermined,
* OSNotificationPermissionDenied,
* OSNotificationPermissionAuthorized,
* OSNotificationPermissionProvisional - only available in iOS 12,
* OSNotificationPermissionEphemeral - only available in iOS 14
* */
function permissionNative(): Promise<OSNotificationPermission>;
/**
* Add listeners for notification click and/or lifecycle events. */
function addEventListener<K extends NotificationEventName>(event: K, listener: (event: NotificationEventTypeMap[K]) => void): void;
/**
* Remove listeners for notification click and/or lifecycle events. */
function removeEventListener<K extends NotificationEventName>(event: K, listener: (event: NotificationEventTypeMap[K]) => void): void;
/**
* Removes all OneSignal notifications.
*/
function clearAll(): void;
/**
* Android Only.
* Removes a single OneSignal notification based on its Android notification integer id.
*/
function removeNotification(id: number): void;
/**
* Android Only.
* Removes all OneSignal notifications based on its Android notification group Id.
* @param {string} id - notification group id to cancel
*/
function removeGroupedNotifications(id: string): void;
}
namespace InAppMessages {
/**
* Add listeners for In-App Message click and/or lifecycle events.
*/
function addEventListener<K extends InAppMessageEventName>(event: K, listener: (event: InAppMessageEventTypeMap[K]) => void): void;
/**
* Remove listeners for In-App Message click and/or lifecycle events.
*/
function removeEventListener<K extends InAppMessageEventName>(event: K, listener: (obj: InAppMessageEventTypeMap[K]) => void): void;
/**
* Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be
* displayed to the user.
*/
function addTrigger(key: string, value: string): void;
/**
* Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should
* be displayed to the user.
*/
function addTriggers(triggers: {
[key: string]: string;
}): void;
/** Remove the trigger with the provided key from the current user. */
function removeTrigger(key: string): void;
/** Remove multiple triggers from the current user. */
function removeTriggers(keys: string[]): void;
/** Clear all triggers from the current user. */
function clearTriggers(): void;
/**
* Set whether in-app messaging is currently paused.
* When set to true no IAM will be presented to the user regardless of whether they qualify for them.
* When set to 'false` any IAMs the user qualifies for will be presented to the user at the appropriate time.
*/
function setPaused(pause: boolean): void;
/** Whether in-app messaging is currently paused. */
function getPaused(): Promise<boolean>;
}
namespace Location {
/** Prompts the user for location permissions to allow geotagging from the OneSignal dashboard. */
function requestPermission(): void;
/** Disable or enable location collection (defaults to enabled if your app has location permission). */
function setShared(shared: boolean): void;
/**
* Checks if location collection is enabled or disabled.
* @param {(value: boolean) => void} handler
*/
function isShared(): Promise<boolean>;
}
namespace Session {
/** Increases the "Count" of this Outcome by 1 and will be counted each time sent. */
function addOutcome(name: string): void;
/** Increases "Count" by 1 only once. This can only be attributed to a single notification. */
function addUniqueOutcome(name: string): void;
/**
* Increases the "Count" of this Outcome by 1 and the "Sum" by the value. Will be counted each time sent.
* If the method is called outside of an attribution window, it will be unattributed until a new session occurs.
*/
function addOutcomeWithValue(name: string, value: string | number): void;
}
}
export { NotificationWillDisplayEvent, NotificationClickEvent, InAppMessage, InAppMessageClickEvent, InAppMessageWillDisplayEvent, InAppMessageDidDisplayEvent, InAppMessageWillDismissEvent, InAppMessageDidDismissEvent, PushSubscriptionState, PushSubscriptionChangedState, UserState, UserChangedState, OSNotificationPermission, };
export { default as OSNotification } from './OSNotification';
export { NotificationClickResult } from './models/NotificationEvents';
export { InAppMessageClickResult } from './models/InAppMessage';