简体   繁体   English

如何在iOS上使用Cordova获得有效的应用内购买(IAP)?

[英]How to get working In-App Purchases (IAP) using Cordova on iOS?

After successful delivery In-App Purchases (IAPs) on Android using Apache Cordova and https://github.com/j3k0/cordova-plugin-purchase I can't get it working properly on iOS. 使用Apache Cordova和https://github.com/j3k0/cordova-plugin-purchase在Android上成功交付应用内购买(IAP)后,我无法在iOS上正常使用它。 The problem is that once the item is clicked the price shows its details etc., but if use clicks "Cancel" then the user can't purchase anything anymore. 问题是,一旦单击该项目,价格就会显示其详细信息等,但是如果用户单击“取消”,则用户将无法再购买任何东西。 Unless restarting the game, as far as I'm aware I should handle rejection/cancellation events. 据我所知,除非重启游戏,否则我应该处理拒绝/取消事件。 Tried these, but so far no success. 尝试了这些,但到目前为止没有成功。

This is how I was trying to handle these events (rejection/cancellation), including playing with store.refresh() in different locations of the code and without it as well: 这就是我试图处理这些事件(拒绝/取消)的方式,包括在代码的不同位置使用store.refresh()以及不使用它的情况:

// Handle rejection and cancel events.
store.when("com.XX.YY.gems5").rejected(function(order) {
  store.refresh();
  that.game.state.start("GemsState");
  store.refresh();
});
store.when("com.XX.YY.gems5").cancelled(function(order) {
  store.refresh();
  that.game.state.start("GemsState");
  store.refresh();
});

Code, which correctly works on Android (the handling wasn't required there in order to work properly): 代码,可在Android上正常工作(不需要处理即可正常工作):

'use strict';
var that = this;

// Prepare product.
store.register({
  id:    "com.XX.YY.gems5",
  alias: "Gems 5",
  type:  store.CONSUMABLE
});

// Purchase product.
store.order("com.XX.YY.gems5");
store.refresh();
store.when("com.XX.YY.gems5").approved(function (order) {
  order.finish();
  store.refresh();

  // Add extra gems.
  localStorage.gems = parseInt(localStorage.gems) + 5; // Add 5 gems.
  that.upgrade_sound.play(); // Play upgrade sound.
  that.game.state.start("GemsState");
  that.menu_items[1].select(); // Select second item.
});

I'm using Phaser 2 & ES5. 我正在使用Phaser 2和ES5。

Apparently this plugin works has sometimes a little bit different behaviour on Android and on iOS, which is the case here. 显然,此插件的工作有时在Android和iOS上会有一些不同的行为,这种情况就是这种情况。 First of all, store.refresh(); 首先, store.refresh(); should be once and at the end of this code. 应该在该代码的末尾。 Below working fine iOS example: 下面的工作良好的iOS示例:

'use strict';
var that = this;

store.register({
  id:    "com.XX.YY.gems5",
  alias: "Gems 5",
  type:  store.CONSUMABLE
});

store.order("com.XX.YY.gems5"); // Initialize purchase.

// Handle approved purchase.
store.when("XX.YY.ZZ.gems20").approved(function (order) {
  // Add extra gems.
  localStorage.gems = parseInt(localStorage.gems) + 20; // Add 20 gems.

  order.finish(); // Finish purchase.
});

store.refresh(); // Refresh the store to start everything.

There are also several drawbacks, which if you'd like to get further insights you can check issue#333 (comment) 还有一些缺点,如果您想获得更多的见解,可以查看issue#333(评论)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM