RevenueCat
Follow this tutorial to set up RevenueCat for in-app purchases
You can find the RevenueCat integration at /providers/RevenueCatProvider.tsx
and it is initialized at /app/(tabs)/_layout.tsx
like this:
Setting up In-App Purchases and Subscriptions
First of all you should create a RevenueCat account for free (e.g. using your Github account) and then create a new project in your account, under which you can add your iOS and Android apps and their respective bundle IDs.
To add IAP to your app you of course need a native app, so make sure you have set up an according app ID for iOS and Android before you continue.
You will also need to to work on your app in App Store Connect for iOS as well as the Google Developer Console for Android where you can add In-App purchases and subscriptions, so make sure you got all the credentials for those accounts.
We are not covering the full process of adding offerings and items to RevenueCat, but you can find a great guide in the RevenueCat getting started guide.
The steps are:
- Create the products in App Store Connect and the Google Developer Console
- Add the products to RevenueCat
- Create entitlements in RevenueCat and add the products to them
- Define offerings in RevenueCat and add the products to them
RevenueCat Provider
We need to load our products and offerings from RevenueCat when the React Native app starts, so we have a RevenueCatProvider
that will do this for us.
We also want to be able to purchase items and restore purchases, so we have these methods as well to the provider as well.
To make sure all of these functions are available to our React app, we create a RevenueCatContext
and export it as a useRevenueCat
hook to be used in our app.
At this point you also need your RevenueCat API keys, which you can find in your RevenueCat project under API Keys. You will need to add them to the .env
file.
This is the structure of the RevenueCatProvider
:
As you can see in the code we have 2 entitlements PRO_MONTHLY
and PRO_ANNUAL
set up. You can add more entitlements in RevenueCat and then add them to the updateCustomerInformation
function.
Also note that we have 2 subscription types monthly
and annual
in the UserState
object.
Paywall
This is the structure of the Paywall
component:
If you have done everything correctly, you should now be able to see your subscription options in the Paywall screen and purchase them.
To access the user subscription state in your app, you can use the useRevenueCat
hook like this:
This is an example of how you can use the useRevenueCat
hook to access the user subscription state in your app.
Conclusion
If you have any problems with setting up RevenueCat, you can always refer to the RevenueCat documentation for more information.
Congrats - you have now set up RevenueCat for in-app purchases in your app!
Other tutorials
Set up development environment
Set up your development environment