Ionic framework Ionic Native InAppPurchase2-Can';无法使用.ready()加载存储

Ionic framework Ionic Native InAppPurchase2-Can';无法使用.ready()加载存储,ionic-framework,ionic2,ionic-native,Ionic Framework,Ionic2,Ionic Native,我在Ionic Native的InAppPurchase2插件上遇到了一些问题,我只想在我的组件加载时加载商店,尽管我运气不好 在我的组件中,我将执行以下操作: ionViewDidLoad() { this.platform.ready().then(() => { this.inAppPurchase2.ready().then(() => this.product = 'InAppPurchase plugin called'); }); }

我在Ionic Native的InAppPurchase2插件上遇到了一些问题,我只想在我的组件加载时加载商店,尽管我运气不好

在我的组件中,我将执行以下操作:

ionViewDidLoad() {
    this.platform.ready().then(() => {
      this.inAppPurchase2.ready().then(() => this.product = 'InAppPurchase plugin called');
    });
  }
根据该插件的Ionic本机页面上的文档,使用
.ready()
函数会返回一个承诺,尽管当我在我的设备上运行该函数时,该代码从未运行过,也没有出现错误

我在其他地方发现了一篇帖子,上面说你可以做一些事情,比如
InAppPurchase2.getPlugin().ready(()=>this.product='InAppPurchase2.getPlugin called')
并直接从模块调用函数,尽管我也不太可能做到这一点,而且我尝试的任何其他方法都会在我的typescript代码中出错


我在这里尝试做的事情有什么遗漏吗?

您尝试做的是异步填充属性

这样做: 创建一个调用插件的ready()函数的函数,并在promise resolve上返回您选择的字符串

    makeAPromiseCall(): Promise<any> {
        return this.InAppPurchase2
            .ready()
            .then(() => 'InAppPurchasePlugin');
    }

我以前在这方面遇到过一些麻烦。有时“准备就绪”事件并不像您预期的那样触发。下面是我用来实现这一点的一些代码

  constructor(public store: InAppPurchase2) {} ...

  this.store.ready().then((status) => {
    this.logger.logEvent('store_ready', {});
    console.log(JSON.stringify(this.store.get(productId)));
    console.log('Store is Ready: ' + JSON.stringify(status));
    console.log('Products: ' + JSON.stringify(this.store.products));
  });
  // This is what is missing...
  this.store.refresh();

希望这能有所帮助。您还必须单独注册产品。我在一份报告中对此做了简要的解释。您需要调用refresh以使存储处于就绪状态。

您如何知道它没有运行?您是否尝试在回调函数中放置日志以查看是否正在调用它?是的,很抱歉,我的html模板中有{{product}以查看它是否显示该消息,但没有显示:/ionic 4也有同样的问题。我注意到添加此.store.refresh();确实会触发事件,但文档明确指出,我们需要尽可能避免使用刷新方法,因为它在计算上非常昂贵,需要用户使用Apple ID登录。参考:
{{product | async}}
  constructor(public store: InAppPurchase2) {} ...

  this.store.ready().then((status) => {
    this.logger.logEvent('store_ready', {});
    console.log(JSON.stringify(this.store.get(productId)));
    console.log('Store is Ready: ' + JSON.stringify(status));
    console.log('Products: ' + JSON.stringify(this.store.products));
  });
  // This is what is missing...
  this.store.refresh();