【问题标题】:iOS inapp purchase plugin return nulliOS 应用内购买插件返回 null
【发布时间】:2015-03-11 05:00:41
【问题描述】:

我正在使用 cordova 在 iOS 商店中制作应用程序,并且我还使用 https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md 来集成应用内购买。

我已经在我的 iTunes 连接上创建了产品并将代码放在

function initStore(){

        if (!window.store) {
            log('Store not available');
            return;
        }

        // Enable maximum logging level
        store.verbosity = store.DEBUG;

        // Enable remote receipt validation
        //store.validator = "https://api.fovea.cc:1982/check-purchase";

        // Inform the store of your products
        alert('registerProducts');


        store.register({
            id:    'com.thegiffary.product.quran_full',
            alias: 'full version',
            type:   store.NON_CONSUMABLE
        });


        // When any product gets updated, refresh the HTML.

        store.when("product").updated(function (p) {
            alert(JSON.stringify(p))
        });

        // When purchase of the full version is approved,
        // show some logs and finish the transaction.
        store.when("full version").approved(function (order) {
            alert('You just unlocked the FULL VERSION!');
            order.finish();
        });

        // The play button can only be accessed when the user
        // owns the full version.
        store.when("full version").updated(function (product) {
            alert(JSON.stringify(product))
        });

        // When the store is ready (i.e. all products are loaded and in their "final"
        // state), we hide the "loading" indicator.
        //
        // Note that the "ready" function will be called immediately if the store
        // is already ready.
        store.ready(function() {
            alert('ready')
        });

        // When store is ready, activate the "refresh" button;
        store.ready(function() {
            alert('refresh-button')
        });

        // Alternatively, it's technically feasible to have a button that
        // is always visible, but shows an alert if the full version isn't
        // owned.
        // ... but your app may be rejected by Apple if you do it this way.
        //
        // Here is the pseudo code for illustration purpose.

        // myButton.onclick = function() {
        //   store.ready(function() {
        //     if (store.get("full version").owned) {
        //       // access the awesome feature
        //     }
        //     else {
        //       // display an alert
        //     }
        //   });
        // };


        // Refresh the store.
        //
        // This will contact the server to check all registered products
        // validity and ownership status.
        //
        // It's fine to do this only at application startup, as it could be
        // pretty expensive.
        alert('refresh');
        store.refresh();
    }

当我在真机上测试代码时,它返回带有空信息的产品(请看图片)

我不确定我在配置应用内产品时是否遗漏了什么?请给我任何建议。

问候。

【问题讨论】:

  • 您能否提供整个代码,因为我正在尝试实现它并进行测试,但无法对其进行正确测试。也让我知道商店验证器的用途。
  • 我在标题 desc 等中也得到了空值,但在我正在注册的状态下。请告诉我你是怎么解决的。

标签: ios cordova plugins


【解决方案1】:

我在开发 android 应用内购买应用时遇到了类似的问题。我将在黑暗中尝试一下,并猜测问题可能是相似的。我的问题是我的产品 ID 与我试图从商店中提取的不匹配。

产品 ID 和类型必须与您在 Apple 和 Google 开发者控制台中定义的产品相匹配。

在我的例子中,当产品加载时,它的字段值与您现在获得的字段值相同。我更改了id,它加载完美。您可能想在 store.register 函数中检查这两个值。

【讨论】:

    猜你喜欢
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    相关资源
    最近更新 更多