Setup
The Intercom React Native wrapper allows you to use Intercom for iOS and/or Intercom for Android in your React Native apps.
If you’re new to Intercom, you’ll need to create an account and start your free trial.
📘 Supported versions
The Intercom React Native wrapper supports version 0.59 of React Native and above.
Intercom for iOS supports iOS 13 and above.
Intercom for Android supports API 21 and above.
Step 1 - Adding the wrapper
To install Intercom you'll need to add the wrapper to your React Native project using the following snippet:
yarn add @intercom/intercom-react-native
npm install @intercom/intercom-react-native
There are separate steps for setting up Android and iOS. If your React Native app does not support Android skip to Step 3.
Step 2 - Android Setup
You'll need to take steps to link the wrapper in your project. These vary based on your apps React Native version.
Using React Native v0.60 and above
If you're using React Native v0.60 or above, the library will be linked automatically
Automatic linking with React Native v0.59
To automatically link the Intercom React Native wrapper in v0.59 of React Native run the following command:
react-native link @intercom/intercom-react-native
Manual linking with React Native v0.59
If you prefer to manually link libraries, add the following snippet to android/settings.gradle
:
include ':intercom-react-native'
project(':intercom-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/@intercom/intercom-react-native/android')
Inside the dependancies block of android/app/build.gradle
add the following line:
dependencies {
implementation project(':intercom-react-native')
}
🚧 Apps using a React Native version below 0.65
React Native versions below 0.65 use OkHttp 3. The Intercom SDK currently uses OkHttp 4.
There is a problem with compatibility between those two versions which may result in crashes.You can fix this by adding an explicit dependency on
okhttp-urlconnection
to dependencies inapp/build.gradle
:dependencies { implementation("com.squareup.okhttp3:okhttp-urlconnection:4.9.1") [...] }
Initialize Intercom
🚧 Minimum Android SDK and build tools versions
The
minSdkVersion
inbuild.gradle
needs to be to21
or greaterIn the dependencies block of the
build.gradle
make sure thatcom.android.tools.build:gradle
is at version4.0.1
You'll need to update the MainApplication.java
class. First add the import com.intercom.reactnative.IntercomModule
at the top of the class.
Then in the onCreate
method, add the snippet below using the apiKey
and appId
found in your workspace settings.
import com.intercom.reactnative.IntercomModule; // <-- Add this line
// ...
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
// ...
IntercomModule.initialize(this, "apiKey", "appId"); // <-- Add this line
// ...
}
Android Permissions
Add below permissions to AndroidManifest.xml
You'll need to include the READ_EXTERNAL_STORAGE permission if you have enabled attachments:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
You can also include VIBRATE to enable vibration in push notifications:
<uses-permission android:name="android.permission.VIBRATE"/>
Step 3 - iOS Setup
If you don't support iOS in your React Native app, you can skip to the configuration step.
Using React Native v0.60 and above
If you're using React Native v0.60 or above, the library will be linked automatically after running the pod install
command.
Manual linking with React Native v0.59
Firstly open your apps .xcworkspace
. If you don't have a .workspace
file open the .xcodeproj
.
Download intercom for iOS and extract the zip
Drag Intercom.xcframework into your project. Make sure "Copy items if needed" is selected and click Finish.
For additional information on iOS manual linking please refer to the React Native developer docs.
Initialize Intercom
Open iOS/AppDelegate.m
and import <IntercomModule.h>
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
// ...
#import <IntercomModule.h> // <-- Add This
Next, in the method didFinishLaunchingWithOptions
you'll need to initialize Intercom. Add the snippet below using the apiKey
and appId
found in your workspace settings.
// ...
self.window.rootViewController = rootViewController;
[IntercomModule initialize:@"apiKey" withAppId:@"appId"]; // <-- Add this (Remember to replace strings with your api keys)
return YES;
}
IOS Permissions
With the exception of apps that only support iOS 14+, when installing Intercom, you'll need to make sure that you have an NSPhotoLibraryUsageDescription entry in your Info.plist.
<key>NSPhotoLibraryUsageDescription</key>
<string>Send photos to support center</string>
For apps that support iOS 13 or lower, this is required by Apple to access the photo library. It is necessary when installing Intercom due to the image upload functionality. Users will be prompted for the photo library permission only when they tap the image upload button.
On iOS 14+, Intercom uses the new PHPickerViewController API which does not require requesting users for photo library permission.
What next?
- Once you've got Intercom installed it's time to use it on your React Native app.
- Enable push notifications so you can send push messages.
- Enable Identity Verification for your React Native app.