React Native Push

Disable/Enable Popups and In App Messages

When a popup notification or an in app message is received by the SDK, it immediately presents the corresponding web view content if the application is in foreground state. If application is in background state when popup is received, SDK presents the web view content whenever application comes to foreground state.

You may want to disable this immediate presentation behavior for cases like when your users watch a video, when they are in the middle of their favorite game level, or when they are about to finish purchasing their order. You can use the following two methods to manage this process:

// Call this method to disable immediate popup presentation
Netmera.disablePopupPresentation();

// Call this method to re-enable immediate popup presentation
Netmera.enablePopupPresentation();

Push Callbacks

Netmera has following push callbacks:

  • Push Register

  • Push Receive

  • Push Open

  • Push Dismiss

  • Push Button Click

Widget Callbacks

Integration of Widget URL Callbacks in React Native for iOS

In React Native, this only needs to be done for iOS. To handle widget URL callbacks in React Native for iOS, the following code must be added to your AppDelegate.m file between @implementation AppDelegate and @end.

// Required code block to handle widget URLs in React Native

- (BOOL)shouldHandleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object {

  return NO;

}

- (void)handleOpenURL:(NSURL *)url forPushObject:(NetmeraPushObject *)object {

  [RNNetmeraRCTEventEmitter handleOpenURL:url forPushObject:object];

}

onWidgetUrlTriggered for React Native

Also, utilize the onWidgetUrlTriggered method in your React Native code to handle the widget URL callback. Here's how:

Netmera.onWidgetUrlTriggered(url => {

console.log('Netmera triggered widget url: ', url);

});

By doing this, you'll be able to incorporate widget URL callback functionality into your iOS React Native app. It's important to note that this information is iOS-specific and pertains to React Native implementation.

Push Receiver

If you want to be informed for one or more of those callback you should follow steps below:

1. Create a new NetmeraPushHeadlessTask.js inside your React Native project.

export const onPushRegister = async (message) => {
    console.log("onPushRegister: ", message);
};

export const onPushReceive = async (message) => {
    console.log("onPushReceive: ", message);
};

export const onPushOpen = async (message) => {
    console.log("onPushOpen: ", message);
};

export const onPushDismiss = async (message) => {
    console.log("onPushDismiss: ", message);
};

export const onPushButtonClicked = async (message) => {
    console.log("onPushButtonClicked: ", message);
};

export const onCarouselObjectSelected = async (message) => {
    console.log("onCarouselObjectSelected: ", message);
};

2. Init NetmeraBroadcastReceiver inside your index.js file.

import {
    onCarouselObjectSelected,
    onPushButtonClicked,
    onPushDismiss,
    onPushOpen,
    onPushReceive,
    onPushRegister
} from "./NetmeraPushHeadlessTask";

Netmera.initBroadcastReceiver(
    onPushRegister,
    onPushReceive,
    onPushOpen,
    onPushDismiss,
    onPushButtonClicked,
    onCarouselObjectSelected
)

// This should be called after Netmera.initBroadcastReceiver method.
AppRegistry.registerComponent(appName, () => App);

If you have custom Firebase Messaging integration, please see usage below.

messaging()
   .getToken(firebase.app().options.messagingSenderId)
   .then(pushToken => {
       Netmera.onNetmeraNewToken(pushToken)
   })

messaging().onMessage(async remoteMessage => {
   if (Netmera.isNetmeraRemoteMessage(remoteMessage.data)) {
       Netmera.onNetmeraFirebasePushMessageReceived(remoteMessage.from, remoteMessage.data)
   }
});

If you have custom Huawei Messaging integration, please see usage below.

HmsPushInstanceId.getToken("")
   .then((result) => {
       Netmera.onNetmeraNewToken(result.result)
   })

HmsPushEvent.onRemoteMessageReceived(event => {
   const remoteMessage = new RNRemoteMessage(event.msg);
   let data = JSON.parse(remoteMessage.getData())
   console.log("onRemoteMessageReceived", data)
   if (Netmera.isNetmeraRemoteMessage(data)) {
       Netmera.onNetmeraHuaweiPushMessageReceived(remoteMessage.getFrom(), data)
   }
})

Last updated