Untitled
unknown
javascript
10 months ago
1.7 kB
3
Indexable
Never
/** * Sample React Native App * https://github.com/facebook/react-native * * @format */ import React, {useEffect} from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View, Button, } from 'react-native'; import {withIAPContext, useIAP, requestPurchase} from 'react-native-iap'; import {Colors} from 'react-native/Libraries/NewAppScreen'; const Container = () => { const { connected, products, promotedProductsIOS, subscriptions, availablePurchases, currentPurchase, currentPurchaseError, initConnectionError, finishTransaction, getProducts, getSubscriptions, getAvailablePurchases, } = useIAP(); const handlePurchase = async (sku: string) => { try { // await requestPurchase({sku}); await requestPurchase({skus: [sku]}); } catch (error) { console.log('[ERROR] handlePurchase', error); } }; useEffect(() => { const fetchGetProducts = async () => { try { await getProducts({skus: ['chatbotpro']}); } catch (error) { console.log('[ERROR] handleGetProducts', error); } }; fetchGetProducts(); }, []); console.log({products}); return ( <> <Button onPress={() => handlePurchase('chatbotpro')} title="Buy" /> </> ); }; function App(): JSX.Element { const isDarkMode = useColorScheme() === 'dark'; const backgroundStyle = { backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, }; return ( <SafeAreaView style={backgroundStyle}> <View style={{backgroundColor: Colors.white}}> <Container /> </View> </SafeAreaView> ); } export default withIAPContext(App);
Leave a Comment