This commit is contained in:
2025-12-16 13:10:50 +08:00
parent 444877fb73
commit fd0ddfd45a
17 changed files with 4751 additions and 3 deletions

View File

@@ -0,0 +1,95 @@
//
// StoreKitState.swift
// StoreKit2Manager
//
// Created by xiaopin on 2025/12/6.
//
import Foundation
import StoreKit
/// StoreKit
public enum StoreKitState: Equatable {
///
case idle
///
case loadingProducts
///
case loadingPurchases
///
case purchasesLoaded
///
case purchasing(String) // ID
///
case purchaseSuccess(String) // ID
///
case purchasePending(String) // ID
///
case purchaseCancelled(String) // ID
///
case purchaseFailed(String, Error) // ID,
///
case restoringPurchases
///
case restorePurchasesSuccess
///
case restorePurchasesFailed(Error)
/// 退
case purchaseRefunded(String) // ID
///
case purchaseRevoked(String) // ID
///
/// - Parameters:
/// - productId: ID
/// - isFreeTrialCancelled: true false
case subscriptionCancelled(String, isFreeTrialCancelled: Bool)
///
case error(Error)
public static func == (lhs: StoreKitState, rhs: StoreKitState) -> Bool {
switch (lhs, rhs) {
case (.idle, .idle),
(.loadingProducts, .loadingProducts),
(.loadingPurchases, .loadingPurchases),
(.purchasesLoaded, .purchasesLoaded):
return true
case (.purchasing(let lhsId), .purchasing(let rhsId)),
(.purchaseSuccess(let lhsId), .purchaseSuccess(let rhsId)),
(.purchasePending(let lhsId), .purchasePending(let rhsId)),
(.purchaseCancelled(let lhsId), .purchaseCancelled(let rhsId)):
return lhsId == rhsId
case (.purchaseFailed(let lhsId, _), .purchaseFailed(let rhsId, _)):
return lhsId == rhsId
case (.restoringPurchases, .restoringPurchases),
(.restorePurchasesSuccess, .restorePurchasesSuccess):
return true
case (.restorePurchasesFailed(let lhsError), .restorePurchasesFailed(let rhsError)):
return lhsError.localizedDescription == rhsError.localizedDescription
case (.purchaseRefunded(let lhsId), .purchaseRefunded(let rhsId)),
(.purchaseRevoked(let lhsId), .purchaseRevoked(let rhsId)):
return lhsId == rhsId
case (.subscriptionCancelled(let lhsId, let lhsIsFreeTrial), .subscriptionCancelled(let rhsId, let rhsIsFreeTrial)):
return lhsId == rhsId && lhsIsFreeTrial == rhsIsFreeTrial
case (.error(let lhsError), .error(let rhsError)):
return lhsError.localizedDescription == rhsError.localizedDescription
default:
return false
}
}
}