I'm testing my app auto-renewable subscriptions but SKPaymentTransaction.transactionState
never changes to .purchased
and it's always .restored
. Everything was working ok but I can get nothing but .restored
since I first called SKPaymentQueue.default().restoreCompletedTransactions()
. I tried deleting the app from my iPhone, relogin into my sandbox account, creating a new sandbox account, restarting Xcode, cleaning the build folder,... What I'm doing wrong? Please find my code below:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
switch transaction.transactionState {
case .purchased:
SKPaymentQueue.default().finishTransaction(transaction)
print(".purchased")
case .failed:
SKPaymentQueue.default().finishTransaction(transaction)
print(".failed")
case .restored:
SKPaymentQueue.default().finishTransaction(transaction)
print(".restored")
default:
break
}
}
}
@IBAction func restore(_ sender: UIBarButtonItem) {
SKPaymentQueue.default().restoreCompletedTransactions()
}
func subscribe() {
if SKPaymentQueue.canMakePayments() {
let payment = SKPayment(product: availableProducts[indexPath.row])
SKPaymentQueue.default().add(payment)
}
}
override func viewDidLoad() {
super.viewDidLoad()
SKPaymentQueue.default().add(self)
}
You should check result of queue