@sfmc/react-native-push
v1.0.0
Published
Push messaging for the Salesforce Marketing Cloud Unified Mobile SDK
Downloads
26
Readme
SFMC Push
SFMC Push Feature for React Native — FCM/APNs registration, push enable/disable, and push token events.
Installation
yarn add @sfmc/react-native-push
# or
npm install @sfmc/react-native-pushiOS:
cd ios && pod installAndroid: no additional steps — Gradle autolinking discovers the module automatically.
Required SDK configuration
- Android — initialize in your
MainApplication.ktviaSFMCSdk.configure(...). See the Android SDK Integration Guide. - iOS — initialize in your
AppDelegate.swiftviaSFMCSdk.initializeSdk(...). See the iOS SDK Integration Guide. - Configure Firebase (Android) and APNs (iOS) credentials before push will deliver.
Usage
import { PushModule } from '@sfmc/react-native-push';
import type { PushApi } from '@sfmc/react-native-push';
const push: PushApi = await PushModule.requestSdk();
push.enablePush();
const token = await push.getPushToken();
const enabled = await push.isPushEnabled();
// Subscribe to token refresh events
const sub = PushModule.getEmitter().addListener('sfmc_push_token_refreshed', ({ token }) => {
console.log('Token refreshed:', token);
});API
| Method | Return | Description |
|--------|--------|-------------|
| enablePush() | void | Enable push notifications |
| disablePush() | void | Disable push notifications |
| isPushEnabled() | Promise<boolean> | Check if push is enabled |
| getPushToken() | Promise<string \| null> | Get the current device push token |
Events
| Event Name | Payload | Platform | Description |
|------------|---------|----------|-------------|
| sfmc_push_token_refreshed | { token: string } | Android only | Emitted when the push token is refreshed |
iOS note: The
sfmc_push_token_refreshedevent is not emitted on iOS. Token refresh on iOS is handled natively viaAppDelegate.application(_:didRegisterForRemoteNotificationsWithDeviceToken:), which passes the token directly toPushFeature.setDeviceToken(_:). UsegetPushToken()to read the current token on demand.
Notes
Push registration requires Firebase configuration on Android (google-services.json in the example app). On iOS, ensure the example target has Push Notifications and Background Modes (Remote Notifications) capabilities enabled in your Apple Developer account.
Versions
- React Native: 0.85.1 (New Architecture mandatory)
- Android: sfmcsdk 3.1.0, pushfeaturemodule 2.0.0
- iOS: SFPushFeatureSDK 2.0.0, MarketingCloud-SFMCSdk 4.0.1
License
BSD 3-Clause. See LICENSE for details.
