我收到“此应用内购买已被购买,它将免费恢复”但未调用委托 updatedTransactions 并且没有任何反应,IAP 不执行。
我已经实现了恢复购买,它工作正常,但是我如何防止用户再次购买非消耗品?为什么不调用委托 updatedTransactions(SKPaymentTransactionState.Restored)?
即使在删除并重新安装应用程序后进行购买也会显示此弹出窗口。
这是我的代码。如果我做错了什么,请告诉我。谢谢
func makePaymentForProduct(product:SKProduct){
let payment = SKPayment.init(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment)
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}
func restorePurchases(){
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}
//MARK: SKProductsRequestDelegate
func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
self.delegate?.didGetProducts(response.products)
}
func request(request: SKRequest, didFailWithError error: NSError) {
self.delegate?.purchaseFailed(error.localizedDescription)
}
//MARK: SKPaymentTransactionObserver
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for (_, transaction) in transactions.enumerate() {
switch (transaction.transactionState) {
case SKPaymentTransactionState.Purchased:
self.completeTransaction(transaction)
break
case SKPaymentTransactionState.Restored:
self.restoreTransaction(transaction)
break
case SKPaymentTransactionState.Failed:
self.failedTransaction(transaction)
break
default:
break
}
}
}
func completeTransaction(transaction:SKPaymentTransaction){
self.delegate?.purchaseSuccessful()
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}
func restoreTransaction(transaction:SKPaymentTransaction){
self.delegate?.purchaseSuccessful()
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}
func failedTransaction(transaction:SKPaymentTransaction){
self.delegate?.purchaseFailed("")
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}
//Restore Purchase
func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue) {
self.delegate?.purchaseRestored()
}
func paymentQueue(queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: NSError) {
self.delegate?.purchaseFailed(error.localizedDescription)
}