在应用程序购买2插件离子3为ios

时间:2018-02-14 10:43:20

标签: ios cordova in-app-purchase ionic3 ionic-native

我在开发离子应用程序方面非常初学,并试图在ios的离子3中集成in-app-purchase2插件。每次我的代码停止并给出错误this.store.when(productId).approved( (product: IAPProduct) => {})都不是函数。

这是我现在所做的尝试:

configurePurchasing() {
let productId;
try {
  if (this.platform.is('ios')) {
    productId = this.product.appleProductId;
  } else if (this.platform.is('android')) {
    productId = this.product.googleProductId;
  }

  // Register Product
  // Set Debug High
  this.store.verbosity = this.store.DEBUG;
  // Register the product with the store
  this.store.register({
    id: productId,
    alias: productId,
    type: this.store.CONSUMABLE
  });

  this.registerHandlers(productId);

  this.store.ready().then((status) => {
    console.log(JSON.stringify(this.store.get(productId)));
    console.warn('Store is Ready: ' + JSON.stringify(status));
    console.warn('Products: ' + JSON.stringify(this.store.products));
  });

  // Errors On The Specific Product
  this.store.when(productId).error( (error) => {
    alert('An Error Occured' + JSON.stringify(error));
  });
  // Refresh Always
  console.log('Refresh Store');
  this.store.refresh();
} catch (err) {
  console.warn('Error On Store Issues' + JSON.stringify(err));
}


 }



 registerHandlers(productId) {
    // Handlers
    this.store.when(productId).approved( (product: IAPProduct) => {
      // Purchase was approved
      product.finish();
    });

this.store.when(productId).registered( (product: IAPProduct) => {
  console.warn('Registered: ' + JSON.stringify(product));
});

this.store.when(productId).updated( (product: IAPProduct) => {
  console.warn('Loaded' + JSON.stringify(product));
});

this.store.when(productId).cancelled( (product) => {
  alert('Purchase was Cancelled');
});

// Overall Store Error
this.store.error( (err) => {
  alert('Store Error ' + JSON.stringify(err));
});


}

  async purchase() {
    let productId;
    if (this.platform.is('ios')) {
      productId = this.product.appleProductId;
    } else if (this.platform.is('android')) {
      productId = this.product.googleProductId;
    }

    console.log('Products: ' + JSON.stringify(this.store.products));
    console.log('Ordering From Store: ' + productId);
    try {
      let product = this.store.get(productId);
      alert('Product Info: ' + JSON.stringify(product));
      // let order = await this.store.order(productId);
      // alert('Finished Purchase');
    } catch (err) {
      console.log('Error Ordering ' + JSON.stringify(err));
    }
  }

从最近8个小时开始,我被困在这一点上。这里有人帮我整合这个插件。如果您有任何与此相关的好教程,请在评论中发布。提前致谢。

0 个答案:

没有答案