React Native SDK Setup

Appgain.io React Native SDK Setup Guide. Works with iOS, Android, and derivatives like Amazon.

Required For Setup

  • Appgain.io Account if you do not already have one
  • Your Appgain.io App ID, available in Project Settings

Generate Credentials

Before setting up the React Native SDK, you must generate the appropriate credentials for the platform(s) you are releasing on:

iOS - Generate an iOS Push Certificate

ANDROID - Generate a Google Server API Key

Installation

Add Appgain.io

at the root dir of you react native project , run this

$ npm install react-native-appgain-sdk-library --save

$ react-native link react-native-appgain-sdk-library

iOS Specific install Instructions

If you're already using Cocoapods, add the following to your Podfile

pod 'react-native-appgain-sdk', path: '../node_modules/react-native-appgain-sdk-library'

Otherwise, setup Podfile according to react native documentation, so the Podfile will look like this:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '10.0'

target 'YourTargetName' do
    pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'Core',
        'CxxBridge', # Include this for RN >= 0.47
        'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
        'RCTText',
        'RCTNetwork',
        'RCTWebSocket', # Needed for debugging
        'RCTAnimation', # Needed for FlatList and animations running on native UI thread
        ]
    # Explicitly include Yoga if you are using RN >= 0.42.0
    pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
    pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
    pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
    pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
#our pod
    pod 'react-native-appgain-sdk', path: '../node_modules/react-native-appgain-sdk-library'

end

Remember to replace YourTargetName with your actual target name.

  • Next, run

$ cd ios

$ pod install

Android Specific Instructions

  • At the very top of your Android project's app/build.gradle, add the following dependencies:
    implementation "androidx.multidex:multidex:2.0.1"
    implementation "com.github.parse-community:Parse-SDK-Android:1.21.0"
    implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.21.0"
    implementation "com.github.parse-community.Parse-SDK-Android:ktx:1.21.0"
    implementation "com.squareup.retrofit2:retrofit:2.5.0"
    implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
    implementation "com.squareup.retrofit2:converter-gson:2.5.0"
  • also make sure that multiDex is enabled:
    android{
        multiDexEnabled = true
    }
  • and in the end of your file add the following line
   apply plugin: 'com.google.gms.google-services'
  • open your project/build.gradle file and add following line under dependencies
 dependencies {  
    classpath 'com.google.gms:google-services:4.2.0'
 }

Initializing Appgain SDK

async () => {
    try {
        await AppgainSDK.initSDK(
            appId,
            apiKey,
            autoConfigure
        )
    } catch (error) {
        console.log("Error", error);
    }
}

Initializing with User

async () => {
        try {
            await AppgainSDK.initUser(
                email,
                password,
                username
        )
    } catch (error) {
        console.log("Error: ", error);
    }
}