I install and linked react native React Native IAP and also upload app in play store after that it create subscription product id But When I am request for get subscription I am getting this error
const items = Platform.select({
ios: [
'dev.products.gas',
'dev.products.premium',
'dev.products.gold_monthly',
'dev.products.gold_yearly',
],
android: ['dev.products.gas',
'dev.products.premium',
'dev.products.gold_monthly',
'dev.products.gold_yearly',],
});
import React, { useEffect } from 'react';
import { View, Text, Button, Platform } from 'react-native';
import { requestPurchase, useIAP } from 'react-native-iap';
const ParchesCode = () => {
const {
connected,
products,
promotedProductsIOS,
subscriptions,
purchaseHistories,
availablePurchases,
currentPurchase,
currentPurchaseError,
initConnectionError,
finishTransaction,
getProducts,
getSubscriptions,
getAvailablePurchases,
getPurchaseHistories,
} = useIAP();
const handlePurchase = async (sku) => {
await requestPurchase({ sku });
};
useEffect(() => {
// ... listen to currentPurchaseError, to check if any error happened
}, [currentPurchaseError]);
useEffect(() => {
// ... listen to currentPurchase, to check if the purchase went through
}, [currentPurchase]);
return (
<View style={{ flex: 1, }}>
<Button
title="Get the products"
onPress={() => getSubscriptions(items)}
/>
{subscriptions.map((product) => (
<View key={product.productId}>
<Text>{product.productId}</Text>
<Button
title="Buy"
onPress={() => handlePurchase(product.productId)}
/>
</View>
))}
<Text>{JSON.stringify(connected)}</Text>
<Text>{JSON.stringify(connected)}</Text>
</View>
);
};
export default ParchesCode;
I am not getting subscriptions when I am calling getSubscriptions() function. I need result after calling this but I am getting error like that -> Possible Unhandled Promise Rejection (id: 0):
skus is required
2
Answers
Here is with working example. there issue is due to change in code but the documentation is not updated.
Here is the product list. the code only for iOS.
For Android, here is a working example of react-native-iap with latest version.