Skip to main content
Question

Is revCat paywall fully functional with React Native CLI? IOS

  • 12 September 2024
  • 1 reply
  • 25 views

Forum|alt.badge.img

My app shows the paywall for a few seconds and then app crashes without any logs.

 

import React, { useEffect, useState } from 'react';

import { View, Text, ActivityIndicator } from 'react-native';

import Purchases from 'react-native-purchases';

import RevenueCatUI from 'react-native-purchases-ui';

 

function Paywall({navigation}) {

const [isRevenueCatConnected, setIsRevenueCatConnected] = useState(false);

const [offerings, setOfferings] = useState(null);

const [error, setError] = useState(null);

 

useEffect(() => {

const connect = async () => {

try {

console.log('Initializing Purchases...');

await Purchases.configure({apiKey: 'my_api_key'});

console.log('Purchases initialized successfully');

setIsRevenueCatConnected(true);

 

// Fetch offerings

const offeringsResponse = await Purchases.getOfferings();

setOfferings(offeringsResponse.current);

} catch (err) {

console.error('Error connecting to RevenueCat:', err);

setError(err);

}

};

connect();

}, []);

 

if (error) {

return (

<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>

<Text>Error connecting to RevenueCat: {error.message}</Text>

</View>

);

}

 

if (!isRevenueCatConnected) {

return (

<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>

<ActivityIndicator size="large" color="#0000ff" />

<Text>Connecting to RevenueCat...</Text>

</View>

);

}

 

if (!offerings) {

return (

<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>

<ActivityIndicator size="large" color="#0000ff" />

<Text>Loading offerings...</Text>

</View>

);

}

 

return (

<View style={{flex: 1}}>

<RevenueCatUI.Paywall

options={{

offering:offerings

}}

onPurchaseCompleted={(purchase) => {

console.log('Purchase completed:', purchase);

navigation.replace("sProcess")

}}

/>

</View>

);

}

 

export default Paywall;

This post has been closed for comments

1 reply

kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 329 replies
  • September 16, 2024

Hey @coder,

What version of the RN Purchases SDK and UI are you currently on, and which Paywalls template are you attempting to display?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings