我安裝并鏈接了 React Native React Native IAP,并在創建訂閱產品 ID 之后在 Play 商店上傳了應用程式但是當我請求獲取訂閱時,我收到了這個錯誤
錯誤
訂閱產品編號
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;
當我呼叫 getSubscriptions() 函式時,我沒有獲得訂閱。呼叫此方法后我需要結果,但出現這樣的錯誤 -> 可能未處理的承諾拒絕(id:0):需要 skus
uj5u.com熱心網友回復:
這是作業示例。問題是由于代碼更改引起的,但檔案未更新。
這是產品串列。代碼僅適用于 iOS。
import {requestPurchase, useIAP, withIAPContext} from 'react-native-iap';
const myProducts = [
'product.example.1',
'product.example.2',
];
const InAppPurchaseScreen = ({navigation}) => {
useEffect(() => {
getProductsAndPurchases();
}, []);
const getProductsAndPurchases = async () => {
try {
await getProducts({skus: myProducts});
} catch (error) {
//console.log("Products error: ", error)
}
};
}
export default withIAPContext(InAppPurchaseScreen);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/537125.html
上一篇:JavaScript代碼的逆序——reactnative
下一篇:AWS中資料庫的最佳備份是什么?
