mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Fixes #2116. Depends on #2134, #2144, #2145. We've known that, especially for sandbox accounts with lots of purchases, the SDK can get flooded with a lot of transactions to process at once. I've been making some improvements for this (like #2115). Another consequence of this behavior, is that we can end up failing due to `StoreKit` throttling us (see #2116): > 2022-12-03 12:31:58.670892+0100 app[673:61074] <SKReceiptRefreshRequest: 0x283edc860>: Finished refreshing receipt with error: Error Domain=ASDErrorDomain Code=603 "Request throttled" UserInfo={NSLocalizedFailureReason=Unified receipt is valid and current, NSLocalizedDescription=Request throttled, AMSServerErrorCode=0} This change avoids that by skipping the refresh if less than 2 seconds have elapsed. I chose 2 to make this a low-ish risk change, with a huge benefit for multiple semi-concurrent requests coming from a big transaction queue.
40 lines
1.1 KiB
Swift
40 lines
1.1 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// ReceiptRefreshPolicy.swift
|
|
//
|
|
// Created by Juanpe Catalán on 7/7/21.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// Determines the behavior when fetching receipts with `ReceiptFetcher`.
|
|
enum ReceiptRefreshPolicy {
|
|
|
|
case always
|
|
case onlyIfEmpty
|
|
case retryUntilProductIsFound(productIdentifier: String,
|
|
maximumRetries: Int,
|
|
sleepDuration: DispatchTimeInterval = .never)
|
|
case never
|
|
|
|
}
|
|
|
|
extension ReceiptRefreshPolicy {
|
|
|
|
/// See `ReceiptFetcher`.
|
|
/// `ReceiptRefreshPolicy.always` won't refresh receipts faster than this interval
|
|
/// to avoid StoreKit errors:
|
|
/// "Finished refreshing receipt with error: Error Domain=ASDErrorDomain Code=603 "Request throttled"
|
|
static let alwaysRefreshThrottleDuration: DispatchTimeInterval = .seconds(2)
|
|
|
|
}
|
|
|
|
extension ReceiptRefreshPolicy: Equatable {}
|