React Native

This module makes it easy to integrate your React Native based mobile app with the Responsys SDK.

In this topic:

Requirements

  • React Native >= 0.61.5
  • React Native CLI >= 2.0.1

Android

  • Android SDK Tools >= 28.0.3

iOS

  • iOS 11 or later

Setup

Before installing the plugin, you must setup your app to receive push notifications. Follow the steps below for your platform:

Android

  1. Get FCM Credentials.
  2. Log in to the Responsys Mobile App Developer Console and enter your FCM credentials (Project ID and Server API Key) for your Android app.
  3. Get the pushio_config.json file generated from your credentials and include it in your project's android/app/src/main/assets folder. You might have to create the directory if it is not already present.

iOS

  1. Generate an Auth Key.
  2. Log in to the Responsys Mobile App Developer Console and enter your Auth Key and other details for your iOS app.
  3. Download the pushio_config.json file generated from your credentials.
  4. Important: Copy PushIOManager.framework and place it in the plugin YOUR_APP_DIR/ios/framework/ folder before adding plugin to project.

Installation

The plugin can be installed with the React Native CLI.

cd <your_react_native_app>
yarn add @oracle/react-native-pushiomanager						

Android

  1. Create a new directory - PushIOManager inside your app's android directory.

  2. Download the SDK native binary and place the .aar file in this android/PushIOManager/ directory.

  3. Inside the android/PushIOManager directory, create a file build.gradle with the following code:

    configurations.maybeCreate("default")

    artifacts.add("default", file('PushIOManager-6.52.aar'))

  4. Add the following to your project-wide settings.gradle file:

    include ':PushIOManager'
    project(':PushIOManager').projectDir = new File(rootProject.projectDir, './PushIOManager')
    

iOS

After installing the plugin, you need to initialize Cocoapods repo,

  1. Go to ios directory of your app, cd YOUR_APP_DIR/ios/
  2. Run pod install
Note: This step will fail if PushIOManager.framework is not available in YOUR_APP_DIR/ios/framework/ folder before adding plugin to project with yarn. Copy the PushIOManager.framework to YOUR_APP_DIR/ios/framework/ and perform Installation step again.

Integration

Android

  1. Open the build.gradle file located in android/app/ and add the following dependency:

     implementation 'com.google.firebase:firebase-messaging:17.3.0' 
    
  2. Open the AndroidManifest.xml file located in android/app/src/main and add the following:

    1. Add permissions above the <application> tag:

      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="${applicationId}.permission.PUSHIO_MESSAGE" />
      <uses-permission android:name="${applicationId}.permission.RSYS_SHOW_IAM" />
      <permission android:name=".permission.PUSHIO_MESSAGE" android:protectionLevel="signature" />
      <permission android:name="${applicationId}.permission.RSYS_SHOW_IAM" android:protectionLevel="signature" />
    2. Add an intent-filter for launching the app when the user taps on a push notification. Add it inside the <activity> tag of MainActivity:

      <intent-filter>
      	<action android:name="${applicationId}.NOTIFICATIONPRESSED" />
      		<category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    3. Add the following code inside the <application> tag:

      <receiver android:enabled="true" android:exported="false" android:name="com.pushio.manager.PushIOUriReceiver">
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <data android:scheme="@string/uri_identifier" />
          </intent-filter>
      </receiver>
      <activity android:name="com.pushio.manager.iam.ui.PushIOMessageViewActivity" android:permission="${applicationId}.permission.SHOW_IAM" android:theme="@android:style/Theme.Translucent.NoTitleBar">
          <intent-filter>
      		<action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.BROWSABLE" />
              <category android:name="android.intent.category.DEFAULT" />
              <data android:scheme="@string/uri_identifier" />
          </intent-filter>
      </activity>
    4. (Optional) Add an intent-filter for Android App Links setup. Add it inside the <activity> tag of MainActivity,

      <intent-filter android:autoVerify="true">
      	<action android:name="android.intent.action.VIEW" />
      	<category android:name="android.intent.category.DEFAULT" />
      	<category android:name="android.intent.category.BROWSABLE" />
      	<data android:host="@string/app_links_url_host" android:pathPrefix="/pub/acc" android:scheme="https" />
      </intent-filter>
  3. Open the strings.xml file located at android/app/src/main/res/values and add the following properties:

    1. Custom URI scheme for displaying In-App Messages and Rich Push content:

      <string name="uri_identifier">pio-YOUR_API_KEY</string>

      You can find the API key in the pushio_config.json that was placed in android/app/src/main/assets earlier during setup.

    2. (Optional) If you added the <intent-filter> for Android App Links in the steps above, then you will need to declare the domain name:

      <string name="app_links_url_host">YOUR_ANDROID_APP_LINKS_DOMAIN</string>

iOS

  1. Open the Xcode project workspace in your ios directory of the React app.
  2. Drag and drop your pushio_config.json into the Xcode project.
  3. Select the root project, and under Capability, add the "Push Notifications" and "Background Modes".

    Capability Image

  4. Implement the below delegate methods in AppDelegate.m:

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:
        (NSData *)deviceToken
    {
        [[PushIOManager sharedInstance]  didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
    }
    
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
        [[PushIOManager sharedInstance]  didFailToRegisterForRemoteNotificationsWithError:error];
    }
    
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
        [[PushIOManager sharedInstance] didReceiveRemoteNotification:userInfo];
    }
    
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:
    (NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
        [[PushIOManager sharedInstance] didReceiveRemoteNotification:userInfo
    fetchCompletionResult:UIBackgroundFetchResultNewData fetchCompletionHandler:completionHandler];
    }
    
    //iOS 10 or later
    -(void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:
    (UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler
    {
        [[PushIOManager sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response
    withCompletionHandler:completionHandler];
    }
    
    -(void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:
    (UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
    {
        [[PushIOManager sharedInstance] userNotificationCenter:center willPresentNotification:notification
    withCompletionHandler:completionHandler];
    }				
    				
    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
       [[PushIOManager sharedInstance] openURL:url options:options];
      return YES;
    }
  5. For In-App Messages and Rich Push Content:

    1. To Enable Custom URI scheme for displaying In-App Messages and Rich Push content follow Step 1 here. You don't need to add the code. You can find the API key in the pushio_config.json that was placed in your Xcode project earlier during setup.

    2. Follow Step 2 here to add the required capabilities in your Xcode project for In-App messages. You don't need to add the code.

  6. For Media Attachments you can follow this guide. Copy and paste the code provided in guide in respective files.

  7. For Carousel Push you can follow this guide. Copy and paste the code provided in guide in respective files.

Usage

The module can be accessed in JS code as follows:

import PushIOManager from 'react-native-pushiomanager';

Configure And Register

  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) => {
                        
              });  
            });
        }
  3. Additional APIs (optional) for iOS only:

    • You can delay registration while app is launching or coming to foreground by implementing below API.

      // Implement before `registerForAllRemoteNotificationTypes` calls.
      PushIOManager.setDelayRegistration(true); 

User Identification

  • Associate an app installation with a user (usually after login):

PushIOManager.registerUserId("userID");
  • When the user logs out:

PushIOManager.unregisterUserId();

Engagements And Conversion

User actions can be attributed to a push notification using:

PushIOManager.trackEngagement(3, properties, (error, response) => {
	      
});

In-App Messages

In-App Messages (IAM) are displayed in a popup window via system-defined triggers like $ExplicitAppOpen or custom triggers. IAM that use system-defined triggers are displayed automatically.

IAM can also be displayed on-demand using custom triggers.

  • Your marketing team defines a custom trigger in Responsys system and shares the trigger-event name with you.
  • Marketer launches the campaign and the IAM is delivered to the device via push or pull mechanism (depending on your Responsys Account settings)
  • When you wish to display the IAM popup, use:

    PushIOManager.trackEvent("custom_event_name", properties);

iOS

These steps are required for iOS In-App Messages:

  1. To Enable Custom URI scheme for displaying In-App Messages and Rich Push content follow the Step 1. You can find the API key in the pushio_config.json that was placed in your Xcode project earlier during setup.

  2. Follow Step 2 to add the required capabilities in your Xcode project for In-App messages.

Message Center

  • Get the Message Center messages list using:

PushIOManager.fetchMessagesForMessageCenter(messageCenterName, (error, response) => {
	
});
  • If any message contains rich-content (HTML), call:

PushIOManager.fetchRichContentForMessage(messageID, (error, response) => {
	      // 'response' is the HTML content
});

Remember to store these messages, since the SDK cache is purgeable.

Geofences and Beacons

If your app is setup to monitor Geofence and Beacons, you can use the following APIs to record in Responsys when a user enters or exits a Geofence/Beacon zone.

PushIOManager.onGeoRegionEntered(geoRegion, (error, response) => {});
PushIOManager.onGeoRegionExited(geoRegion, (error, response) => {});
PushIOManager.onBeaconRegionEntered(beaconRegion, (error, response) => {});
PushIOManager.onBeaconRegionExited(beaconRegion, (error, response) => {});

Notification Preferences

Preferences are used to record user choices for push notifications. The preferences should be pre-defined in Responsys before being used in your app.

  • Declare the preference beforehand in the app:

PushIOManager.declarePreference(key, label, preferenceType, (error, response) => {
	
});
  • Once a preference is declared successfully, you may save the preference using:

PushIOManager.setPreference(key, value, (error, success) => {
	
});

Do not use this as a persistent (key/value) store since this data is purgeable.

Changing Notification Icon and Color (Android Only)

Responsys SDK uses the app icon as the icon for notifications. You can change this by using the following two APIs:

PushIOManager.setNotificationLargeIcon("ic_notification_large");
PushIOManager.setNotificationSmallIcon("ic_notification_small");

  • Icon name should be provided without the file extension.

  • Icon images should be present in your app's drawable or mipmap directory, i.e. android/app/src/main/res/drawable or android/app/src/main/res/mipmap.

It is also possible to change the notification small icon color by using the following API:

PushIOManager.setNotificationSmallIconColor("#d1350f");

Upgrades

6.50.1 to 6.51

With the release of v6.51.0, we have simplified the plugin integration process.

Due to this change, you will need to perform the following steps one-time only.

Android

  • Remove the existing PushIOManager-6.50.1.aar file from app/src/main/libs directory.

  • Follow the setup instructions given in the Installation section above.

iOS

  • Find and remove the following line from the YOUR_APP_DIR/ios/Podfile:

     pod 'PushIOManager', :path => '<PATH_TO_node_modules/@oracle/react-native-pushiomanager/PushIOManager/_Directory>'`
  • Create a framework directory inside YOUR_APP_DIR/ios/ directory.

  • Copy the latest PushIOManager.framework inside YOUR_APP_DIR/ios/.

  • Install the latest plugin yarn add @oracle/react-native-pushiomanager.

Learn more

Multiple Push SDKs