我正在使用ti.storekit来进行app结算。一切似乎都有效,但是当我运行以下代码时:
Storekit.requestProducts(["FooPro"], function (evt)
{
Ti.API.info('evt:' + JSON.stringify(evt, undefined, 2));
//hideLoading();
if (!evt.success)
{
alert('ERROR: We failed to talk to Apple!');
}
else if (evt.invalid)
{
alert('ERROR: We requested an invalid product!');
}
else
{
item = evt.products;
Ti.API.info('gotProducts:' + JSON.stringify(item, undefined, 2));
success(item[0]);
}
});
我得到了成功的回复,但没有产品:
evt:{
"type": "callback",
"products": [
{}
],
"source": {},
"success": true
}
所以没有产品,只是默默地失败了。在iTunes中,在产品中,我有一个产品ID为FooPro
的应用内商品(虽然它正在等待审核)。我不确定我还做错了什么。一切似乎工作,我只是回到一个空产品阵列,我不知道为什么。
这也导致错误,以便在我打电话时
// product = {} since the above returned it as empty
Storekit.purchase(product);
它错误并告诉我这个:
Passing individual args to `purchase` is DEPRECATED. Call `purchase` passing in a dictionary of arguments.
addTransactionObserver` should be called before `purchase`
编辑:产品,当使用Ti.API.info()输出显示为空的内容时。然而,在设备上使用测试帐户登录itunes之后,产品仍显示为空,但是当我进行更多调试时,产品对象实际上似乎是:
{'My product description'}
所以当我打电话时
Storekit.purchase(product)
它似乎真的在呼唤
Storekit.purchase({'My product description'})
所以它似乎失败了,因为购买呼叫永远不会触发transactionState
事件监听器。
环境: - iPhone :5,4s
感谢您的帮助。
答案 0 :(得分:1)
哇......我已经进一步玩弄它了,而且还有一些东西在继续......
即使您获得[{}]
产品,products[0].title
也会带回实际的产品名称。
它好像在那里,但隐藏在跟踪声明中。
您需要做的就是发送{product:e.products [0]}进行购买,并且瞧:
Storekit.requestProducts(productIDs, function(e) {
Ti.API.info("GOT PRODUCTS : "+JSON.stringify(e));
// 'GOT PRODUCTS : {"type":"callback","products":[{}],"source":{},"success":true}'
Ti.API.info('PROD TITLE : '+e.products[0].title);
// 'PROD TITLE : My IAP product'
Storekit.purchase({product:e.products[0]});
// You need to implement 'transactionState' and addTransactionObserver to carry on from here - see the example code in the module package for that
});
并确保设置Storekit.autoFinishTransactions = false;
- 或者在用户购买产品后您无法获得最终购买活动。