首页 > 解决方案 > cordova-plugin-purchase:即使在调用命令之后,iOS 也不做任何事情

问题描述

我们正在使用Ioniccordova-plugin-purchase(也称为 In App Purchase 2)来实现购买订阅。Android 运行良好——iOS 给我们带来了很多问题。

使用产品名称调用order函数应该会显示 iOS 购买弹出窗口,并且购买应该像往常一样继续。

但是,调用该order函数后,订阅产品的状态变为requested但之后没有任何反应。没有弹出窗口出现。奇怪的是,就在昨天,我们能够购买该产品,并且在订阅到期后,我们能够再次购买它。它工作得很好。但是,今天产品再次过期后,点击下单功能只是将产品的状态更新为,requested但之后没有任何反应。购买在 Android 上也运行得非常好——只是 iOS 非常奇怪并且总是产生错误和问题。有时,当我们更改沙盒帐户并使用新帐户时,它可以工作,但有时,它会突然停止工作。

我们尝试尽可能地简化代码,以至于只有这些是重要的部分:

    // this just automatically sets the validator to the correct URL which changes depending on the user's ID.
    this.subscriptions.add(
      this.status.userData.subscribe(data => {
        this.userData = data;
        this.store.validator = `https://xxxxxxxxxxx/api/app/users/${ data.id }/purchased`;
      })
    );

    this.store.register([
      {
        id: this.MONTHLY_SUBSCRIPTION,
        type: this.store.PAID_SUBSCRIPTION
      },
      {
        id: this.YEARLY_SUBSCRIPTION,
        type: this.store.PAID_SUBSCRIPTION
      }
    ]);

    this.store.error((error) => {
      console.log('ERROR', error);
    });

    this.store.when(this.YEARLY_SUBSCRIPTION).updated((p) => {
      this.yearly = p;
      console.log('yearly', p.state);
    });

    this.store.when(this.MONTHLY_SUBSCRIPTION).updated((p) => {
      this.monthly = p;
      console.log('month', p.state);
    });

    this.store.when(this.YEARLY_SUBSCRIPTION)
        .approved(p => p.verify())
        .verified(p => p.finish())
        .owned(p => this.continue(true, p.id));

    this.store.when(this.MONTHLY_SUBSCRIPTION)
        .approved(p => p.verify())
        .verified(p => p.finish())
        .owned(p => this.continue(true, p.id));

    this.store.refresh();

调用this.store.order(this.MONTHLY_SUBSCRIPTION);不会做任何事情。有趣的部分是调用this.store.order(this.YEARLY_SUBSCRIPTION);确实显示了 iOS 购买弹出窗口。没有错误输出或任何东西。我们之前也尝试过使用this.store.autoFinishTransactions = true;this.store.refresh();但似乎没有任何作用。

我们最近运气不好,如果有人可以提供有关如何解决此问题的建议或提示(可能是插件中的错误?我确实尝试过提交问题,但是...)

非常感谢您,如果需要,我很乐意提供任何进一步的信息。

标签: ioscordovaionic-frameworkin-app-purchasecordova-plugins

解决方案


根据插件的文档,store.register()接受一个对象,而不是一个数组。这可能就是为什么它只注册最后一个产品。

store.register({
    id: "cc.fovea.inapp1",
    alias: "full version",
    type: store.NON_CONSUMABLE
});

https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#register

我能想到的另一种可能性是您MONTHLY_SUBSCRIPTION的价值可能与您在应用商店连接上的应用内购买项目的产品 ID 不匹配。


推荐阅读