React Native SDK for OneSignal's push notification, email, SMS, and in-app messaging service
—
Essential SDK initialization and configuration functions for app startup and user lifecycle management.
Initialize the OneSignal SDK with your application ID. This must be called during app startup.
/**
* Initializes the OneSignal SDK. This should be called during startup of the application.
* @param appId - Your OneSignal application ID
*/
function initialize(appId: string): void;Usage Example:
import { OneSignal } from "react-native-onesignal";
// Initialize during app startup
OneSignal.initialize("your-onesignal-app-id");Manage user sessions for cross-device user identification and tracking.
/**
* 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.
* @param externalId - External user identifier from your system
*/
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;Usage Examples:
// User logs in - identify them for cross-device tracking
OneSignal.login("user123");
// User logs out - clear identification
OneSignal.logout();Manage privacy consent for GDPR compliance and data protection regulations.
/**
* For GDPR users, your application should call this method before setting the App ID.
* @param required - Whether privacy consent is required
*/
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.
* @param granted - Whether consent has been granted
*/
function setConsentGiven(granted: boolean): void;Usage Example:
// For GDPR compliance - call before initialize()
OneSignal.setConsentRequired(true);
// After user grants consent
OneSignal.setConsentGiven(true);
// Then initialize
OneSignal.initialize("your-app-id");Configure logging and debugging output for development and troubleshooting.
namespace Debug {
/**
* Enable logging to help debug if you run into an issue setting up OneSignal.
* @param 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 visualLogLevel - Sets the logging level to show as alert dialogs
*/
function setAlertLevel(visualLogLevel: LogLevel): void;
}Usage Example:
import { OneSignal, LogLevel } from "react-native-onesignal";
// Enable verbose logging for development
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
// Show errors as alert dialogs
OneSignal.Debug.setAlertLevel(LogLevel.Error);Install with Tessl CLI
npx tessl i tessl/npm-react-native-onesignal