SDK Integration

React Native SDK [v 0.2.1]

Package Installation

Install the package using Yarn or NPM

(back to top)

Changes to note from v0.3.0 onwards

Personalisation has been added to the SDK which requires TenantID to be passed as a parameter while initialising the SDK. Also an option to set a delay for in-app messages has been added. Please see the SDK initialisation in Android (step7) and in iOS integration (step 6).

The TenantID can be copied from the Pushologies portal under the SETTINGS -> API KEYS tab. Failing to add this parameter would mean that the Personalisation values cannot be set and processed by the SDK.

Android Integration

  1. Generate and upload your certificate

  2. Add the following to your root level build.gradle file

    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.3.15'
    }
    
  3. Add the following to your app level build.gradle file

    apply plugin: 'com.google.gms.google-services'
    
  4. Place the google-services.json got from Step 1 in the Android app folder ex: project-dir/android/app

  5. You have to integrate Firebase Service as explained here

  6. You must request the Notifications, Locations permissions for user to get the notifications and geofence notifications to come through. You can refer example code NOTE: You may have to delay the permission requests if you are using useEffect on Android 13 as one of the permission may not be shown if you do it immediately. You can use third party functions like useFocusEffect to achieve this.

      const requestNotificationPermission = async () => {
        const notificationPerm = PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS;
        const granted = PermissionsAndroid.RESULTS.GRANTED;
        try {
          const grantedPerm =
            (await PermissionsAndroid.requestMultiple([notificationPerm]))[
              notificationPerm
            ] === granted;
          console.log(`Notification Permisson:${grantedPerm}\n`);
          return grantedPerm;
        } catch (err) {
          console.warn(err);
        }
        return false;
      };
    
      const requestLocationPermissionAndroid = async () => {
        const finePerm = PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION;
        const bckgPerm = PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION;
        const granted = PermissionsAndroid.RESULTS.GRANTED;
        try {
          const grantedFine =
            (await PermissionsAndroid.requestMultiple([finePerm]))[finePerm] ===
            granted;
          const grantedBckg =
            (await PermissionsAndroid.requestMultiple([bckgPerm]))[bckgPerm] ===
            granted;
          console.log(
            `Fine Location:${grantedFine}\nBackground Location:${grantedBckg}\n`,
          );
          return grantedFine && grantedBckg;
        } catch (err) {
          console.warn(err);
        }
        return false;
      };
    
  7. There is no way you can initialise the SDK from the React native layer yet. So you need to initialise it in native side. You can get the API key and secret from the Pushologies portal. Initialise your SDK as follows in the Application class. Application class is usually found in this path: /android/app/src/main/java/com/project_name/MainApplication.java

Please include your own notification icon files in the drawable folder of the Android project