React Native - Subscription Status

Learn how to get info about user subscription status and grant access to the premium features of the app using Adapty React Native SDK

With Adapty you don't have to hardcode product ids to check subscription status. You just have to verify that the user has an active access level. To do this, you have to call adapty.purchases.getInfo() method:

try {
  const info = await adapty.purchases.getInfo()
  // or
  adapty.purchases.getInfo({ forceUpdate: true })
} catch (error: AdaptyError) {}

Request parameters:

  • {forceUpdate}Force update. Optional. If you want to force the SDK to fetch fresh data. Data from a local cache would be used otherwise. Default is false

Response parameters:

  • infoPurchaser info: an AdaptyPurchaserInfo object. It contains info about access levels, subscriptions, and non-subscription purchases. Generally, you have to check only access level status to determine whether the user has premium access to the app.

Below is a complete example of checking the user's access level.

try {
  const info = await adapty.purchases.getInfo();
  // "premium" is an identifier of default access level
  if (info?.accessLevels['premium']?.isActive) {
    // grant access to premium features
  }
} catch (error: AdaptyError) {}

📘

You can have multiple access levels per app. For example, if you have a newspaper app and sell subscriptions to different topics independently, you can create access levels "sports" and "science". But most of the time, you will only need one access level, in that case, you can just use the default "premium" access level.

Read more about access levels in the Access Level section.

Listening for subscription status updates

useEffect(() => {
  adapty.addEventListener('onInfoUpdate', () => {
    ...
  });
    
  return () => adapty.removeAllListeners();
},[]);

🚧

Make sure to set up App Store Server Notifications for iOS and Real-time Developer Notifications (RTDN) for Android to receive subscription updates without significant delays.


Did this page help you?