Titanium:InApp购买Iphone(Ti.Storekit)

时间:2013-12-18 12:04:20

标签: ios iphone titanium appcelerator storekit

我使用Ti.Storekit模块,我遇到了问题。我无法使用它,嗯,这是我的代码:

Storekit.requestProducts(['com.rotary.imrotarian.upgradeyears1', 'com.rotary.imrotarian.upgradeyears2'], function (evt) {
    if (!evt.success) {
        alert('ERROR: We failed to talk to Apple!');
    }
    else if (evt.invalid) {
        alert('ERROR: We requested an invalid product!');
        alert(evt);
    }
    else {
        success(evt.products[0]);
        success(evt.products[1]);

        var dialog = Titanium.UI.createOptionDialog({
                title: APP.L('inapp_purchase_store_name'),
                options: [product1.title + ' - ' + product1.formattedPrice, product2.title + ' - ' + product2.formattedPrice, APP.L('Cancel')],
                cancel:3
            });
            dialog.show();

            dialog.addEventListener('click',function(e)
            {
              if (e.index == 0)
              {
                purchaseProduct(product1);
              }

              if (e.index == 1)
              {
                purchaseProduct(product2);
              }

            }); 
    }
});

当我使用它时,它不是苹果错误,它是一个evt错误。 如果我打印evt警报是这样的:

{
invalid= {
    "com.rotary.imrotarian.upgradeyears1",
    "com.rotary.imrotarian.upgradeyears2"
};
products = {
};
source = "[object TiStorekitProductRequest]";
success = 1;
type = callback;
}

}

purchaseProduct功能是:

function purchaseProduct(product) {
    Ti.API.info('----- CALL APPLE PURCHASE ' + JSON.stringify(product.identifier));
    Storekit.purchase(product, 1, function (evt) {
        Ti.API.info('----- Apple answer purchase: ' + JSON.stringify(evt));
        switch (evt.state) {
            case Storekit.FAILED:
                alert(APP.L('inapp_purchase_store_error_buy_failed'));                  
                break;
            case Storekit.PURCHASED:
            case Storekit.RESTORED:
                //var receipt = Ti.Utils.base64encode(evt.receipt).text; 
                //Ti.App.Properties.setString('recibo', receipt);
                alert(APP.L('inapp_purchase_store_recipt_verified'));
                markProductAsPurchased(product.identifier);
                break;
        }
    }); 
};

不知道我做错了什么?但似乎它没有检测到这些产品。

希望有人能帮助我

感谢。

0 个答案:

没有答案