Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React本机应用内购买Android_Android_React Native_Google Play_In App Purchase_In App Billing - Fatal编程技术网

React本机应用内购买Android

React本机应用内购买Android,android,react-native,google-play,in-app-purchase,in-app-billing,Android,React Native,Google Play,In App Purchase,In App Billing,我正在尝试将应用程序内购买(或谷歌喜欢称之为“应用程序内账单”)添加到我的React原生应用程序中 我所做的: 在Google Play控制台中创建了一个产品(标识符为“unlock_premium” 纱线添加反应本机iap(库) 将下面的代码添加到我的应用程序中的组件 在物理设备上使用react native run android和从Google Play控制台发布到Alpha测试进行测试 注意:应用程序已签名,并且在清单文件中启用了计费权限,react native iap的版本为0.3.

我正在尝试将应用程序内购买(或谷歌喜欢称之为“应用程序内账单”)添加到我的React原生应用程序中

我所做的:

  • 在Google Play控制台中创建了一个产品(标识符为“unlock_premium”
  • 纱线添加反应本机iap
    (库)
  • 将下面的代码添加到我的应用程序中的组件
  • 在物理设备上使用react native run android和从Google Play控制台发布到Alpha测试进行测试
  • 注意:应用程序已签名,并且在清单文件中启用了计费权限,
    react native iap
    的版本为0.3.23

    问题: 当运行调试构建时,
    console.log()
    只打印产品是
    未定义的
    ,而
    productInfo
    在运行Alpha部署版本时不会显示在屏幕上(因此产品也未定义)。
    products
    变量只是一个空数组

    (try-语句似乎成功了,因为我看不到从中打印出任何错误。)

    从“react native iap”导入InAppPurchase;
    const itemSKUs=Platform.select({
    安卓:[
    “com.kimer.unlock\u premium”//我也尝试过“unlock\u premium”
    ]
    })
    ...
    建造师(道具){
    超级(道具);
    此.state={
    modalVisible:错误,
    premiumProduct:未定义
    };
    }
    ...
    异步组件didmount(){
    试一试{
    等待购买。准备();
    const products=wait InAppPurchase.getProducts(itemSKUs);
    log(“获取产品的完成调用”);
    console.log(产品[0]);
    this.setState({premiumProduct:products[0]});
    }捕捉(错误){
    控制台。警告(错误);
    }
    }
    ...
    render(){
    让productInfo;
    if(this.state.premiumProduct!==未定义){
    productInfo=(
    {this.state.premiumProduct}
    {this.state.premiumProduct.localizedPrice}
    {this.state.premiumProduct.currency}{this.state.premiumProduct.productID}
    {this.state.premiumProduct.title}
    {this.state.premiumProduct.description}
    );
    }
    返回(
    ...
    {productInfo}
    ...
    );
    }
    
    已解决:
    它现在对我起作用了,做了所有这些事情,仍然得到一个空数组?有什么想法吗?@MayankBaiswar你找到什么解决方案了吗?愚蠢的问题..有没有可能在没有生产android商家帐户和经批准和部署的应用程序的情况下在android应用程序上测试react native iap?如何?这可以用来强迫免费应用程序上的用户您是在一周后还是在使用该应用10次后获得一次性许可证?
    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>
            );
    }