我有一个非常基本,但令人兴奋的问题,我无法弄清楚。以下是:
问题简介
我从IAP得到了receipt
对象,但不能得到productId
子对象。它返回undefined
?怎么会发生这种事?receipt.productID返回未定义的,尽管接收对象是ok的,并且有一个未定义的productId子对象。它应该完美地返回'lite_plan‘,但它返回未定义的?
initIAP = () => {
RNIap.initConnection().then(() => {
RNIap.flushFailedPurchasesCachedAsPendingAndroid().catch(() => {
}).then(() => {
console.log('open listener')
this.purchaseUpdateSubscription = purchaseUpdatedListener((purchase: InAppPurchase | SubscriptionPurchase | ProductPurchase ) => {
console.log('purchaseUpdatedListener', purchase);
var receipt = purchase.transactionReceipt;
if (receipt) {
console.log('receipt >> ' + receipt)
console.log('product id >> ' + receipt.productId)
AsyncStorage.setItem('activeplan_local', receipt.productId).then(() => {
.....
控制台输出:
receipt >> {"orderId":"****","packageName":"com.****","productId":"lite_plan","purchaseTime":1617193622753,"purchaseState":0,"purchaseToken":"*****","autoRenewing":true,"acknowledged":false}
product id >> undefined
你能给我看看这个问题吗?
多谢你们的支持
发布于 2021-03-31 12:49:59
你可以试试这个-
this.purchaseUpdateSubscription = purchaseUpdatedListener(async (purchase: InAppPurchase | SubscriptionPurchase | ProductPurchase ) => {
console.log('purchaseUpdatedListener', purchase);
// use const instead of var
const receipt = await purchase.transactionReceipt;
if (receipt) {
console.log('receipt >> ' + receipt)
console.log('product id >> ' + receipt.productId)
AsyncStorage.setItem('activeplan_local', receipt.productId).then(() => {
https://stackoverflow.com/questions/66888085
复制相似问题