Files
purchases-ios/Sources/Misc/StoreKit2Setting.swift
T
NachoSoto 23afeb96d0 Added StoreKit2Setting to replace useStoreKit2IfAvailable (#1467)
This adds a third case `disabled` that allows tests to explicitly disable StoreKit 2.
Some types, like `TrialOrIntroPriceEligibilityChecker` and `TransactionsManager` always used SK2 because the implementation was better. But this meant that tests couldn't explicitly disable it (other than calling the internal methods directly).

This allows #1464 to be a lot simpler but being able to use the public `Purchases` methods, but forcing the implementation to use SK1.

Note that this is purely an implementation detail. `StoreKit2Setting` is `internal`, and the public API still only exposes the same boolean.

This basically solves [CF-497] too, since those tests will now force `TrialOrIntroPriceEligibilityChecker` to run the SK1 implementation.

[CF-497]: https://revenuecats.atlassian.net/browse/CF-497?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-04-11 11:41:47 -07:00

52 lines
1.4 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
//
// StoreKit2Setting.swift
//
// Created by Nacho Soto on 4/6/22.
/// Defines when StoreKit 2 APIs may be used
enum StoreKit2Setting {
/// Never use SK2
case disabled
/// Use SK2 (if available in the current device) only for certain APIs that provide a better implementation
/// For example: intro eligibility, determining if a receipt has purchases, managing subscriptions.
case enabledOnlyForOptimizations
/// Enable SK2 in all APIs if available in the current device
case enabledForCompatibleDevices
}
extension StoreKit2Setting {
init(useStoreKit2IfAvailable: Bool) {
self = useStoreKit2IfAvailable
? .enabledForCompatibleDevices
: .enabledOnlyForOptimizations
}
static let `default`: Self = .enabledOnlyForOptimizations
}
extension StoreKit2Setting: CustomDebugStringConvertible {
var debugDescription: String {
switch self {
case .disabled: return "disabled"
case .enabledOnlyForOptimizations: return "optimizations-only"
case .enabledForCompatibleDevices: return "enabled"
}
}
}