ios - RNIap.getPurchaseHistory() 在 iOS 上总是返回一个空数组
问题描述
总是返回一个空RNIap.getPurchaseHistory
数组。无论我是在应用程序启动时还是在购买后调用。在componentDidMount
我执行以下操作:
async componentDidMount() {
await RNIap.initConnection();
this.purchaseUpdateSubscription = purchaseUpdatedListener(
async purchase => {
try {
// send purchase to the server
const savedPurchase = await savePurchase(purchase);
// finish transaction if server returned truthly value
if (savedPurchase) {
await RNIap.finishTransaction(purchase, true);
// always returns en empty array
console.log('Purchase history', await RNIap.getPurchaseHistory())
}
} catch (e) {
console.log('Error: ', e);
}
}
});
}
buyProduct
功能:
buyProduct = async productId => {
try {
await RNIap.requestPurchase(productId, false);
} catch (e) {
console.warn('Error: ', e);
}
};
购买后,我收到消息:
你都准备好了。
您的购买成功
[环境:沙盒]。
也许问题可能出在与代码库无关的另一个地方?
解决方案
偶然发现我认为可能是您的解决方案:
将 RNIap.getPurchaseHistory() 包裹在 initConnection() 和 endConnection() 调用周围。在请求购买历史记录之前,也许还要给 RNIap.finshTransaction 更多时间来完成以确保包括最新的购买。
// CODE
await RNIap.initConnection();
const purchase_history = await RNIap.getPurchaseHistory()
console.log(purchase_history)
RNIap.endConnection()
推荐阅读
- google-colaboratory - 如何在 google colab 中加载 30GB 的数据集
- c# - 在客户端 PC WPF 中显示 RDLC 报告
- java - 预期 BEGIN_ARRAY 但在改造中是 BEGIN_OBJECT
- php - 消息:在浮点数上调用成员函数 result_array()
- ruby-on-rails - 启动 Rails 服务器时的雾弃用警告
- javascript - 重构解构语句
- blogger - 如何优化 blogspot 搜索结果的标题和描述标签(数据:blog.searchQuery)?
- ios - 通过 iOS amazon sdk 在 s3 上缓慢上传图像
- c# - 无法投射 IEnumerable
到 IEnumerable - javascript - 调用从动态创建的表中传递文件名的函数