React Native
What is RevenueCat?
RevenueCat provides a backend and a wrapper around StoreKit and Google Play Billing to make implementing in-app purchases and subscriptions easy. With our SDK, you can build and manage your app business on any platform without having to maintain IAP infrastructure. You can read more about how RevenueCat fits into your app or you can sign up free to start building.
Installation
Make sure that the deployment target for iOS is at least 13.4 and Android is at least 6.0 (API 23) as defined here.
Option 1: React-Native package
Purchases for React-Native can be installed either via npm or yarn. We recommend using the latest version of React Native, or making sure that the version is at least greater than 0.64.
Option 1.1: Using auto-linking
Recent versions of React Native will automatically link the SDK, so all that's needed is to install the library.
- npm
- yarn
npm install --save react-native-purchases
yarn add react-native-purchases
Option 1.2: Manual linking
- npm
- yarn
npm install --save react-native-purchases
yarn add react-native-purchases
After that, you should link the library to the native projects by doing:
- Shell
react-native link react-native-purchases
Option 2: Using Expo
react-native-purchases
works with with any Expo project when using a development build. A development build helps you iterate as quickly as possible and provides a more flexible, reliable, and complete development environment. It also enables you to only write JavaScript/TypeScript while letting Expo tools and services take care of everything else. The Android and iOS apps are built using Expo's build service and generate development and production binaries for testing and releasing.
As of mid 2021, projects created with Expo now support in-app payments and are compatible with react-native-purchases
. Running npx expo install react-native-purchases
is all that needs to be done before you can start implementing RevenueCat into your app.
Note: Expo's docs state that in-app purchases will only work on real Android and iOS devices which can make debugging more difficult. You can view the RevenueCat debug logs on Android with LogCat and iOS with Console.app.
For more information, see our blog post here.
Bare workflow
If you are using bare workflow (that is, your project is created using react-native init
), install expo
into your project and leverage Expo CLI to use Expo tooling and services.
The bare workflow gives developers complete native control but also allows the use of Expo libraries and services. The bare workflow is similar to a project you would get from npx react-native init
.
If you're planning on ejecting from Expo to use the bare workflow, upgrade your Expo version first, then eject. It'll save you a whole lot of hassle.
Get started with the bare workflow here.
Set the correct launchMode for Android
Depending on your user's payment method, they may be asked by Google Play to verify their purchase in their (banking) app. This means they will have to background your app and go to another app to verify the purchase. If your Activity's launchMode
is set to anything other than standard
or singleTop
, backgrounding your app can cause the purchase to get cancelled. To avoid this, set the launchMode
of your Activity to standard
or singleTop
in your Android app's AndroidManifest.xml
file, like so:
- AndroidManifest.xml
<activity
android:name="com.your.Activity"
android:launchMode="standard" /> <!-- or singleTop -->
You can find Android's documentation on the various launchMode
options here.
Import Purchases
You should now be able to import Purchases
.
- React Native
import Purchases from 'react-native-purchases';
Don't forget to include the BILLING
permission in your AndroidManifest.xml file
- AndroidManifest.xml
<uses-permission android:name="com.android.vending.BILLING" />
Don't forget to enable the In-App Purchase capability for your project under Project Target -> Capabilities -> In-App Purchase
Next Steps
- Now that you've installed the Purchases SDK in your React Native app, get started by initializing an instance of Purchases →