【发布时间】:2014-02-14 13:51:17
【问题描述】:
我在应用程序购买中使用这个出色的 iOS 插件https://github.com/j3k0/PhoneGap-InAppPurchase-iOS
这些是消耗品。
一切正常,我可以看到产品并成功购买它们,但是发生了一些奇怪的事情。似乎如果我开始购买,然后取消,这个取消的购买将被添加到队列中,并且在重新启动应用程序时,它将尝试完成所有这些上述取消的购买。它可以达到您有 5 10 甚至 20 条“无法连接到 iTunes 商店”消息要单击的程度,然后您才能再次使用应用内购买(取决于您取消了多少交易)。重要的是要注意这不仅仅是“无法连接到商店”,我故意输入了错误的密码并得到了“无法登录”错误,然后该错误也被附加到了这个错误队列中。
以下是 xcode 中针对每个实例重复的日志的相关部分
InAppPurchase[objc]:付款交易已更新: 2014-02-14 13:35:15.737 MyAPP [228:60b] InAppPurchase [objc]:错误 2 无法连接到 iTunes Store 2014-02-14 13:35:15.738 MyAPP [228:60b] InAppPurchase [objc]:状态:PaymentTransactionStateFailed 2014-02-14 13:35:15.739 MyAPP[228:60b]
以及我用于应用内购买的代码
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Empty
}
function IAPOK() {
// empty
}
var IAP = {
list: [ "purchase250", "purchase500" ]
};
IAP.load = function () {
// Check availability of the storekit plugin
if (!window.storekit) {
console.log("In-App Purchases not available");
return;
}
// Initialize
storekit.init({
debug: true, // Enable IAP messages on the console
noAutoFinish: true,
ready: IAP.onReady,
purchase: IAP.onPurchase,
restore: IAP.onRestore,
error: IAP.onError
});
};
IAP.onReady = function () {
//load all product data.
storekit.load(IAP.list, function (products, invalidIds) {
IAP.products = products;
IAP.loaded = true;
for (var i = 0; i < invalidIds.length; ++i) {
console.log("Error: could not load " + invalidIds[i]);
}
IAP.render();
});
};
IAP.render = function (el) {
var el = document.getElementById('in-app-purchase-list');
if (IAP.loaded) {
var html = "<p>";
for (var id in IAP.products) {
var prod = IAP.products[id];
html += "<p>" +
"<h3>" + prod.title + "</h3>" +
"<p>" + prod.description + "</p>" +
"<button type='button' class='formbutton' " +
"onclick='IAP.buy(\"" + prod.id + "\")'>" +
prod.price + "</button>" +
"</p>";
}
html += "</p>";
el.innerHTML = html;
}
else {
el.innerHTML = "In-App Purchases not available.";
}
};
IAP.onPurchase = function (transactionId, productId) {
storekit.finish(transactionId);
if (productId === 'purchase250'){
navigator.notification.alert('Thanks for your purchase, your account balance has been updated', IAPOK, 'MyAPP', 'OK'); }
if (productId ==='purchase500'){
navigator.notification.alert('Thanks for your purchase, your account balance has been updated', IAPOK, 'MyAPP', 'OK'); }
};
IAP.onError = function (errorCode, errorMessage) {
navigator.notification.alert(errorMessage, IAPOK, 'MyAPP', 'OK');
};
IAP.onFinish = function (transactionId, productId) {
console.log('Finished transaction for ' + productId + ' : ' + transactionId);
};
IAP.buy = function (productId) {
storekit.purchase(productId);
};
【问题讨论】:
标签: javascript ios iphone cordova in-app-purchase