0

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
        }
    }
}
jdleung
  • 1,088
  • 2
  • 10
  • 26
  • Does your app use Apple-hosted content or non-renewing subscriptions? Otherwise, a much simpler restore workflow could be to use `SKReceiptRefreshRequest`. Assuming that you read the receipt anyway. – Paul Schröder Feb 19 '21 at 13:29
  • `SKReceiptRefreshRequest` return one receipt, but it only restore auto-renewable subscription. It's pity. I need to find a better way in case of adding other types of In-app. – jdleung Feb 21 '21 at 14:46

0 Answers0