React Native Basic Integration
Steps for basic integration of the Branch React Native SDK into your React Native app.
1. Configure Branch Dashboard
Start by configuring the Branch Dashboard for your application:
Make sure to configure your default link settings as part of the setup process.
2. Install Branch
Please choose one of the following integration methods to install the Branch React Native SDK into your app.
Pure React Native App
Use one of the following commands to install the module:
NPM
npm install react-native-branch
Yarn
yarn add react-native-branch
Note: The react-native-branch
module requires your react-native
version to be greater than or equal to 0.60
.
Native iOS App With CocoaPods
- Add the following code to your Podfile in order to install Branch using CocoaPods:
platform :ios, '11.0'
target 'APP_NAME' do
# if swift
use_frameworks!
pod 'react-native-branch', path: '../node_modules/react-native-branch'
end
- Run the
pod install
command to regenerate thePods
project with the new dependencies. Please note that the location ofnode_modules
relative to your Podfile may vary.
Expo Framework
Branch does support applications that use Expo, but please note that we do not maintain the react-native-branch plugin for Expo. This means we cannot fix any issues that arise related to this plugin.
To learn more, visit Expo's react-native-branch
plugin GitHub page.
3. Configure App
Complete the app configuration steps for the relevant platform(s) you are using.
iOS Configuration
To configure iOS:
- Configure bundle identifier.
- Configure associated domains.
- Configure
Info.plist
file. - Add a
branch.json
file to your project, which you will use to access certain Branch configuration settings:- Create an empty file called
branch.json
. - Add the file to your project using Xcode. Within your project, navigate to File → Add Files.
- Select the
branch.json
file and make sure every target in your project that uses Branch is selected. - Click Add.
- Create an empty file called
Android Configuration
To configure Android:
- Add dependencies.
- Configure
AndroidManifest.xml
file. - Add a
branch.json
file to your project, which you will use to access certain Branch configuration settings.- Create an empty file called
branch.json
. - Place the file in the
src/main/assets folder
of your app.
- Create an empty file called
4. Initialize Branch
Use the code samples in this section to initialize the SDK in your application(s).
Branch Initialization on iOS
To initialize Branch on iOS, add the following to your app's AppDelegate file:
Branch Initialization on Android
To initialize Branch on Android, you need to:
- Add Branch to your
MainApplication.kt
file (orMainApplication.java
for older apps):
- Add Branch to your
MainActivity.kt
file (orMainActivity.java
for older apps):
5. Validate Integration
Use the guides below to validate that your SDK integration(s) are properly configured:
iOS
Android
Common Build Problems
- Be sure to update from < 2.0.0 if your app used an earlier version of
react-native-branch
. In version 2.x, the native SDKs are embedded in the NPM module and must not also be added from elsewhere (Gradle, CocoaPods, etc.). - Note that when using the
React
pod in a native app, the name of the native SDK pod isBranch-SDK
, notBranch
, and it comes fromnode_modules
, not the CocoaPods repo. - Starting with React Native 0.40, all external iOS headers in Objective-C must be imported as
#import <PackageName/Header.h>
. This applies to React Native headers as well as the<react-native-branch/RNBranch.h>
header from this SDK. - If you upgraded from RN < 0.40 manually, without adjusting your Xcode project settings, you may still be importing headers with double quotes. This probably indicates a problem with your settings.
- The
react-native-git-upgrade
tool from NPM may be used to update dependencies as well as project settings. - On Android, when using Proguard in release builds, depending on your build settings, it may be necessary to add one or both of these lines to your
android/app/proguard-rules.pro
file:-dontwarn com.crashlytics.android.answers.shim.** -dontwarn com.google.firebase.appindexing.**
Updated about 1 month ago
Once you've validated your SDK integration, try getting started with Branch Events or Branch Deep Links: