我正在尝试添加应用程序购买(或者谷歌喜欢这样称呼它;“在应用程序计费”)到我的反应本土应用。
我所做的:
yarn add react-native-iap (这库)react-native run-android进行测试,并通过将其发布到Google控制台的Alpha测试注意:应用程序已签名,清单文件中启用了计费权限,react-native-iap的版本为0.3.23。
问题:在运行调试版本时,console.log()只打印产品是undefined,而productInfo在运行Alpha版本时不会在屏幕上显示(因此产品在那里也没有定义)。products变量只是一个空数组。
( try-statement似乎成功了,因为我看到它没有打印错误。)
import InAppPurchase from "react-native-iap";
const itemSKUs = Platform.select({
android: [
"com.kimer.unlock_premium" // I've also tried just "unlock_premium"
]
})
...
constructor(props) {
super(props);
this.state = {
modalVisible: false,
premiumProduct: undefined
};
}
...
async componentDidMount() {
try {
await InAppPurchase.prepare();
const products = await InAppPurchase.getProducts(itemSKUs);
console.log("finished call to get products");
console.log(products[0]);
this.setState({premiumProduct: products[0]});
} catch (err) {
console.warn(err);
}
}
...
render() {
let productInfo;
if (this.state.premiumProduct !== undefined) {
productInfo = (
<Text>{this.state.premiumProduct}
{this.state.premiumProduct.localizedPrice}
{this.state.premiumProduct.currency} {this.state.premiumProduct.productID}
{this.state.premiumProduct.title}
{this.state.premiumProduct.description}</Text>
);
}
return (
<View>
...
{productInfo}
...
</View>
);
}发布于 2018-05-03 15:17:10
解决了:,它现在为我工作!我尝试了几件事,但我不知道让它起作用的关键是什么--这就是我所做的:
import InAppPurchase from "react-native-iap;" to "import * as InAppPurchase from 'react-native-iap';"更改了导入语句https://stackoverflow.com/questions/50139161
复制相似问题