Solved

Initial launch of App presentPaywallIfNeeded returns what ?

  • 19 March 2024
  • 2 replies
  • 47 views

Badge

I’m trying to understand what this would return if the user is NOT connected to the internet when they first launch the app after a clean install.

 const payWallResult = await RevenueCatUI.presentPaywallIfNeeded({
requiredEntitlementIdentifier: "pro",
});

What im suspecting is that it returns PAYWALL_RESULT.NOT_PRESENTED, but this is wrong ,since when you are subscribed and not need the paywall this would be the case as well. So it returns this status if A) you are not connected to the internet (only on clean install) and B) you have a subscription already.

 

This can make users that know this trick - just disable internet and have full access to all features, by just disabling internet for this app. Any advice ?

icon

Best answer by wes_clark 21 March 2024, 18:29

View original

This post has been closed for comments

2 replies

Userlevel 2
Badge +5

Hi! Yes, if the Internet is offline, the paywall will not be displayed as a connection is necessary to make a purchase. I would recommend directly checking if the necessary entitlement is active within the CustomerInfo in order to distinguish between these two cases instead. Here is our documentation on how the SDK handles caching if you are interested.

Badge

Thank you - I came up with this solution which now works

I call isSubscribedAndShowPaywall() when I need to access a feature and it will bring up the paywall. Then after the paywall is showed or not - I double check the entitlement and then return if the user can access this or not.

Before I was relying on the paywall result, but this didnt work as restore didnt always work on sandbox and the paywall wasn’t presented at all when offline.

const isSubscribedAndShowPaywall = async () => {
const payWallResult = await RevenueCatUI.presentPaywallIfNeeded({
requiredEntitlementIdentifier: "pro",
});

//now check if user has entitlement (we cant rely on paywallResult)
const hasEntitlement = await getEntitlementStatus();

//warn user that they need internet
if (isOnline === false && hasEntitlement === false) {
Alert.alert(
"Error",
"This is a pro feature, and you require an internet connection to proceed."
);
}

return hasEntitlement;
};


const getEntitlementStatus = async () => {
try {
const customerInfo = await Purchases.getCustomerInfo();

if (typeof customerInfo.entitlements.active["pro"] !== "undefined") {
return true;
}
} catch (e) {
// Error fetching customer info
return false;
}
};