Multiple Push SDKs

This topic provides steps for configuring your React Native app to identify and display push notifications from Responsys when using multiple push SDKs in the same app. Before proceeding, ensure that you have followed through the React Native setup guide.

In this topic:

Overview

The Responsys React Native plugin supports co-existing with other push providers' React Native plugins within the same app. While we do not certify this behavior with other providers individually, as long as the other plugins follow the standard React Native Plugin/Apple Development Guidelines, there should be no issues with integrations.

iOS

Overview

The steps below walkthrough how to configure your React Native app to identify and display push notifications from Responsys when using multiple push SDKs in the same iOS app. Any other push SDKs from other providers must follow the standard Apple Development Guidelines. These SDKs must also provide a way to disable Swizzling, or forward the delegate method calls to the app to make themselves compatible with other SDKs.

Note: Some push providers and vendors depend on Swizzling, and do not provide APIs to disable Swizzling for their React Native Plugins. Disabling Swizzling might break their plugins or functionality. Check with your push provider before continuing.

Step 1: Disable Swizzling

Refer to your push provider's documentation to disable Swizzling or the automatic setup of Swizzling. Some React Native plugins allow automatic setup with a Swizzling method. If this Swizzling method is enabled, your non-Responsys SDKs can automatically intercept all of the AppDelegate methods and take control of your app push notification setup. Therefore, Swizzling needs to be disabled for the Responsys SDK to co-exist with other SDKs.

Step 2: Setup and Register

Next, you must configure the Responsys SDK plugin, register the SDK with APNs, and register the SDK with the Responsys platform.

// Your React Native App -(JS) 
 
1. //Configure the SDK,
 
 PushIOManager.configure("your-pushio_config.json", (error, response) => {
        
 });
 
 
2. //Once the SDK is configured, register the app with Responsys,
//Combine above steps and use Platform check to detect the platform.
 
 import { Platform } from 'react-native';
  
 if (Platform.OS === 'android') {
    PushIOManager.registerApp(true, (error, response) => {
              
        });
 } else {
    PushIOManager.registerForAllRemoteNotificationTypes((error, response) => {
              
            PushIOManager.registerApp(true, (error, response) => {
         
        }); 
    });
 }
         ```			

Step 3: Implement Delegate

Implement the below delegate methods in AppDelegate.m step from the React Native Plugin Setup instructions with the code below. Other push provider's SDKs plugins should also provide similar APIs. You'll need to call the specific SDK's APIs based on the push payload received by the device. When a new push notification is received by the device, it is important to identify the source of the push notification, and direct the payload to the correct SDK. The Responsys Mobile SDK v6.42 and above provides convenient methods to identify if the push notification originated from Responsys, to then forward the push notification to the Responsys Mobile SDK.

// AppDelegate.m in Xcode
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:
(NSData *)deviceToken
{
    [[PushIOManager sharedInstance]  didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
 
    //** Call Other SDKs ``didRegisterForRemoteNotificationsWithDeviceToken:`` or equivalent method provided by SDK vendor
}
 
 
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
 
    [[PushIOManager sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
 
    //** Call Other SDKs ``didFailToRegisterForRemoteNotificationsWithError:`` or equivalent method provided by SDK vendor 
}
 
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
     
    if ([[PushIOManager sharedInstance] isResponsysPayload: userInfo]) {
        [[PushIOManager sharedInstance] didReceiveRemoteNotification:userInfo];
    } else {
        //** Call Other SDKs ``didReceiveRemoteNotification:`` or equivalent method provided by SDK vendor
    }
}
 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    if ([[PushIOManager sharedInstance] isResponsysPayload:userInfo ]) {
        [[PushIOManager sharedInstance] didReceiveRemoteNotification:userInfo
                                               fetchCompletionResult:UIBackgroundFetchResultNewData fetchCompletionHandler:completionHandler];
    } else {
        //** Call Other SDKs ``didReceiveRemoteNotification:fetchCompletionHandler:``  or equivalent method provided by SDK vendor  
    }
}
 
// UNUserNotificationCenterDelegate methods
 
- (void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
     
    if ([[PushIOManager sharedInstance] isResponsysPayload: notification.request.content.userInfo ]) {
        [[PushIOManager sharedInstance] userNotificationCenter:center willPresentNotification:notification
                                         withCompletionHandler:completionHandler];
    } else {
        //** Call Other SDKs ``willPresentNotification:``  or equivalent method provided by SDK vendor  
    }
}
 
- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    if ([[PushIOManager sharedInstance] isResponsysPayload: response.notification.request.content.userInfo ]) {
        [[PushIOManager sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response
                                         withCompletionHandler:completionHandler];
    } else {
        //** Call Other SDKs ``didReceiveNotificationResponse:``  or equivalent method provided by SDK vendor  
    }
}
 		

 

Android

Setup your Android app to include the Firebase Messaging Plugin using this guide.

Important: Please do not upgrade to v6 of the Firebase Messaging Plugin as it is incompatible with the Responsys Mobile React-Native plugin.

Handling Incoming Push Notifications

Since there are multiple React Native plugins trying to access the push notifications, you need to intercept the incoming push notifications and forward it to the correct plugin.

Foreground Push Notifications

When a new push notification is received by the device, the onMessage() method is called. Here, it is important to identify the source of the push notification and direct the payload to the correct plugin. Here's an example implementation:

import messaging from '@react-native-firebase/messaging';
import PushIOManager from '@oracle/react-native-pushiomanager';
 
componentDidMount() {
 
    messaging().onMessage(async remoteMessage => {
             
        PushIOManager.isResponsysPush(remoteMessage, (error, response) => {
                 
            if (response) {
 
                // Push notification received from Responsys.
                PushIOManager.handleMessage(remoteMessage);
 
            } else {
 
                // Not a Responsys push notification, handle it appropriately.
            }
        });
    });
}					

Background Push Notifications

To intercept background push notifications, add a Firebase Background Handler to the index.js file. Here's a sample implementation:

import messaging from '@react-native-firebase/messaging';
import PushIOManager from '@oracle/react-native-pushiomanager';
import { AppRegistry } from 'react-native';
 
messaging().setBackgroundMessageHandler(async remoteMessage => {
             
    PushIOManager.isResponsysPush(remoteMessage, (error, response) => {
                 
        if (response) {
 
            // Push notification received from Responsys.
            PushIOManager.handleMessage(remoteMessage);
 
        } else {
 
            // Not a Responsys push notification, handle it appropriately.
        }
    });
});
 
AppRegistry.registerComponent(appName, () => App);				

Learn more

React Native