Push Messaging

This section provides API reference details for the Push Messaging module in the React Native unified plugin.

enablePush 

Enables push messaging in the native Marketing Cloud SDK.

Syntax 

1PushMessagingSdkModule.enablePush();

Returns 

  • void

Example 

1import { PushModule } from "@sfmc/react-native-push";
2import type { PushApi } from "@sfmc/react-native-push";
3
4const push: PushApi = await PushModule.requestSdk();
5push.enablePush();

See Also 

disablePush 

Disables push messaging in the native Marketing Cloud SDK.

Syntax 

1PushMessagingSdkModule.disablePush();

Returns 

  • void

Example 

1import { PushModule } from "@sfmc/react-native-push";
2import type { PushApi } from "@sfmc/react-native-push";
3
4const push: PushApi = await PushModule.requestSdk();
5push.disablePush();

See Also 

isPushEnabled 

Returns the current state of the push-enabled flag in the native Marketing Cloud SDK.

Syntax 

1PushMessagingSdkModule.isPushEnabled();

Returns 

  • Promise<boolean> - A promise that resolves to whether push messaging is enabled.

Example 

1import { PushModule } from "@sfmc/react-native-push";
2import type { PushApi } from "@sfmc/react-native-push";
3
4const push: PushApi = await PushModule.requestSdk();
5const enabled = await push.isPushEnabled();

See Also 

getPushToken 

Returns the token that Marketing Cloud uses to send push messages to the device.

Syntax 

1PushMessagingSdkModule.getPushToken();

Returns 

  • Promise<string \| null> - A promise that resolves to the push token string, or null.

Example 

1import { PushModule } from "@sfmc/react-native-push";
2import type { PushApi } from "@sfmc/react-native-push";
3
4const push: PushApi = await PushModule.requestSdk();
5const token = await push.getPushToken();
6
7const sub = PushModule.getEmitter().addListener("sfmc_push_token_refreshed", ({ token }) => {
8  console.log("Token refreshed:", token);
9});
10
11sub.remove();

See Also