Introduction
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 Project ID, available in Project Settings
- Generate iOS and Android Push Credentials
Generate Credentials
Before setting up the React Native SDK, you must generate the appropriate credentials for the platform(s) you are releasing on:
Installation
- Add Appgain.io at the root dir of you react native project , run this
$ npm install rn-appgain-sdk --save
- Link Appgain.io
$ react-native link rn-appgain-sdk
iOS 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 install instruction
- At the very top of your Android project's app/build.gradle, add the following dependencies:
implementation 'io.appgain:sdk:3.1.1-appcompat-beta'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.github.parse-community:Parse-SDK-Android:1.18.5'
implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.18.5"
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.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'
}
- Make sure you added the required permissions to your manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!--Optional>
- inside your application tag add
<service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="com.parse.fcm.ParseFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_app_notfication" />
- Create new class MyPushReceiver which extend AppGainPushReceiver and implement onReceive method
public class MyPushReceiver extends AppGainPushReceiver {
@Override
protected void onReceive(Context context, ReceiveStatus receiveStatus, Intent intent) {
// doing some action after receiving
}
}
- register the receiver in your application tag in Manifest file
<application
....
>
<receiver
android:name=".MyPushReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
....
</application>
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);
}
}