消耗品应用内购买已购买
Consumable In App Purchase Already Purchased
我在我的应用程序中添加了消耗品应用内购买。我可以购买它,但是当我再次尝试购买时,它说我已经购买了它,所以它会再次下载。该类型绝对是消耗品。
我哪里错了?
谢谢
func purchasePoints(sender:AnyObject) {
//Purchase
buyConsumable()
}
func buyConsumable(){
print("About to fetch the products");
// We check that we are allow to make the purchase.
if (SKPaymentQueue.canMakePayments())
{
var productID:NSSet = NSSet(object: "com.companyname.appname.coins");
var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
productsRequest.delegate = self;
productsRequest.start();
print("Fething Products");
}else{
print("can not make purchases");
}
}
func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
print("got the request from Apple")
var count : Int = response.products.count
if (count>0) {
var validProducts = response.products
var validProduct: SKProduct = response.products[0] as SKProduct
if (validProduct.productIdentifier == "com.companyname.appname.coins") {
print(validProduct.localizedTitle)
print(validProduct.localizedDescription)
print(validProduct.price)
buyProduct(validProduct);
} else {
print(validProduct.productIdentifier)
}
} else {
print("nothing")
}
}
func buyProduct(product: SKProduct){
print("Sending the Payment Request to Apple");
var payment = SKPayment(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment);
}
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [SKPaymentTransaction]) {
print("Received Payment Transaction Response from Apple");
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
print("Product Purchased");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
case .Failed:
print("Purchased Failed");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
// case .Restored:
//[self restoreTransaction:transaction];
default:
break;
}
}
}
}
您是否在控制台日志中看到此消息:
print("Received Payment Transaction Response from Apple");
和
print("Product Purchased");
或
print("Purchased Failed");
?
如果没有,好像你没有添加
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
在将付款添加到队列之前的某处。
尝试将其添加到您的 buyConsumable 方法中。
用现有交易试试这个,但要确保它是可消费的。
我在我的应用程序中添加了消耗品应用内购买。我可以购买它,但是当我再次尝试购买时,它说我已经购买了它,所以它会再次下载。该类型绝对是消耗品。 我哪里错了? 谢谢
func purchasePoints(sender:AnyObject) {
//Purchase
buyConsumable()
}
func buyConsumable(){
print("About to fetch the products");
// We check that we are allow to make the purchase.
if (SKPaymentQueue.canMakePayments())
{
var productID:NSSet = NSSet(object: "com.companyname.appname.coins");
var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
productsRequest.delegate = self;
productsRequest.start();
print("Fething Products");
}else{
print("can not make purchases");
}
}
func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
print("got the request from Apple")
var count : Int = response.products.count
if (count>0) {
var validProducts = response.products
var validProduct: SKProduct = response.products[0] as SKProduct
if (validProduct.productIdentifier == "com.companyname.appname.coins") {
print(validProduct.localizedTitle)
print(validProduct.localizedDescription)
print(validProduct.price)
buyProduct(validProduct);
} else {
print(validProduct.productIdentifier)
}
} else {
print("nothing")
}
}
func buyProduct(product: SKProduct){
print("Sending the Payment Request to Apple");
var payment = SKPayment(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment);
}
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [SKPaymentTransaction]) {
print("Received Payment Transaction Response from Apple");
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
print("Product Purchased");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
case .Failed:
print("Purchased Failed");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
// case .Restored:
//[self restoreTransaction:transaction];
default:
break;
}
}
}
}
您是否在控制台日志中看到此消息:
print("Received Payment Transaction Response from Apple");
和
print("Product Purchased");
或
print("Purchased Failed");
?
如果没有,好像你没有添加
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
在将付款添加到队列之前的某处。 尝试将其添加到您的 buyConsumable 方法中。
用现有交易试试这个,但要确保它是可消费的。