Only One auto-renewable subscription implemented in app, recently I found it will return lots of receipts when restore purchased. I got 38 transactions, but each transaction receive a same receipt with 38 transactions inside, there will be 38*38 = 1444. It means that expires_date_ms
needs to be check out from 1444 arrays.
So I try to limit the number of validation, it will not reduce the network traffic since request is completed when updatedTransactions is called, just want to know if it's a good choice add a limitation.
var restoreIds = [String]()
func restoreTransactions() {
restoreIds.removeAll()
SKPaymentQueue.default().restoreCompletedTransactions()
}
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for trans in transactions {
let id = trans.payment.productIdentifier
switch trans.transactionState {
case .purchased, .restored:
if restoreIds.firstIndex(of: id) == nil {
restoreIds.append(id)
receiptValidation(id)
}
SKPaymentQueue.default().finishTransaction(trans)
case .failed:
SKPaymentQueue.default().finishTransaction(trans)
default:
break
}
}
}