【问题标题】:cordova InAppPurchase Plugin gives error "ERROR TypeError: Cannot read property 'getProducts' of undefined"cordova InAppPurchase 插件给出错误“错误类型错误:无法读取未定义的属性'getProducts'”
【发布时间】:2020-05-14 17:27:33
【问题描述】:

我在我的应用程序中使用cordova in-app-purchase plugin,但收到“ERROR TypeError: Cannot read property 'getProducts' of undefined”的错误

.ts 文件是这样的:

window['plugins'].inAppPurchase.getProducts(productIds).then(products => {
      console.log('got products: ', JSON.stringify(products));
      self.buyProducts(products[0].productId);

    });

陷入困境。提前致谢。

【问题讨论】:

    标签: angular typescript cordova npm cordova-plugins


    【解决方案1】:

    您使用 inAppPurchase 类对象的方式不正确,请按照以下方法使其工作。
    要添加插件,请运行以下命令:
    cordova plugin add cordova-plugin-inapppurchase

    成功安装和配置插件后。在所需组件中导入并使用插件如下。

    import { InAppPurchase } from '@ionic-native/in-app-purchase/ngx';
    并像这样注入构造函数

    constructor(
        private iap: InAppPurchase,
      ) {
            this.iap
            .getProducts(PaymentPage.PRODUCT_IDS)
            .then((products) => {
              console.log('Get products', JSON.stringify(products));                            
             })
            .catch((err) => {
              console.log(JSON.stringify(err));          
            });
    }
    

    希望它能解决你的问题。

    【讨论】:

    • 我没有使用 ionic 进行跨平台实现
    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 2021-12-03
    • 2021-11-22
    • 2018-07-12
    • 2021-12-16
    相关资源
    最近更新 更多