这是我第一次在我的项目中使用react本机iap。我安装了这个库,没有任何问题。我有几个问题。
import * as RNIap from 'react-native-iap';
const itemSkus = Platform.select({
ios: ['stackoverflow_ex'],
android: ['stackoverflow_ex']
});
export default class Buy extends Component {
state= {
products:[],
count:0
}
async componentDidMount() {
try {
const products: Product[] = await RNIap.getProducts(itemSkus);
this.setState({ products });
} catch(err) {
console.warn(err); // standardized err.code and err.message available
}
}
requestPurchase = async (sku: string) => {
try {
await RNIap.requestPurchase(sku, false);
this.setState({ count:this.state.count+1 });
} catch (err) {
console.warn(err.code, err.message);
}
}
click = () => {
this.requestPurchase('stackoverflow_ex')
}
render() {
const {item} = this.props;
return (
<TouchableOpacity onPress={() => this.click()} />
);
}
}发布于 2020-07-16 18:21:58
对于android,您需要在Google中上传您的apk。如果没有,那么您就不能在应用程序中测试Google计费。您可以做的是上传apk并在Internal test track下发布。审查过程将需要2-3天。然后你就可以做测试了。
如需更多阅读,请查看此链接
发布于 2021-01-17 22:21:37
乍一看,我要说的是,至少缺少了initConnection。确保代码正确完成的最佳方法--查看github:https://github.com/dooboolab/react-native-iap/blob/master/IapExample/App.js中的示例
https://stackoverflow.com/questions/62939292
复制相似问题