mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
StoreKit 2: enabled by default (#1922)
The main change is `StoreKit2Setting.default` is now `enabledForCompatibleDevices`, but I've also made sure that all places in the codebase are derived from this value.
This commit is contained in:
1 parent
30b9670972
commit
0ee540aac4
5 files changed
+28
-9
No files matched your search
@@ -162,16 +162,16 @@ extension PurchaseStrings: CustomStringConvertible {
|
||||
"a transaction date - this is an issue with the App Store. Unix Epoch will be used instead. \n" +
|
||||
"Transactions in the backend and in webhooks are unaffected and will have the correct timestamps. " +
|
||||
"This is a bug in StoreKit 1. To prevent running into this issue on devices running " +
|
||||
"iOS 15+, watchOS 8+, macOS 12+, and tvOS 15+, " +
|
||||
"you can set `usesStoreKit2IfAvailable` to true when calling `configure`."
|
||||
"iOS 15+, watchOS 8+, macOS 12+, and tvOS 15+, make sure " +
|
||||
"`usesStoreKit2IfAvailable` is set to true when calling `configure`."
|
||||
|
||||
case .sktransaction_missing_transaction_identifier:
|
||||
return "There is a problem with the SKPaymentTransaction missing " +
|
||||
"a transaction identifier - this is an issue with the App Store." +
|
||||
"Transactions in the backend and in webhooks are unaffected and will have the correct identifier. " +
|
||||
"This is a bug in StoreKit 1. To prevent running into this issue on devices running " +
|
||||
"iOS 15+, watchOS 8+, macOS 12+, and tvOS 15+, " +
|
||||
"you can set `usesStoreKit2IfAvailable` to true when calling `configure`."
|
||||
"iOS 15+, watchOS 8+, macOS 12+, and tvOS 15+, make sure " +
|
||||
"`usesStoreKit2IfAvailable` is set to true when calling `configure`."
|
||||
|
||||
case .could_not_purchase_product_id_not_found:
|
||||
return "makePurchase - Could not purchase SKProduct. " +
|
||||
|
||||
@@ -93,7 +93,7 @@ public extension Purchases {
|
||||
appUserID: appUserID,
|
||||
observerMode: observerMode,
|
||||
userDefaults: userDefaults,
|
||||
useStoreKit2IfAvailable: false
|
||||
useStoreKit2IfAvailable: StoreKit2Setting.default.usesStoreKit2IfAvailable
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ extension StoreKit2Setting {
|
||||
: .enabledOnlyForOptimizations
|
||||
}
|
||||
|
||||
static let `default`: Self = .enabledOnlyForOptimizations
|
||||
static let `default`: Self = .enabledForCompatibleDevices
|
||||
|
||||
}
|
||||
|
||||
@@ -49,6 +49,15 @@ extension StoreKit2Setting {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns: `true` if SK2 is enabled.
|
||||
var usesStoreKit2IfAvailable: Bool {
|
||||
switch self {
|
||||
case .disabled: return false
|
||||
case .enabledOnlyForOptimizations: return false
|
||||
case .enabledForCompatibleDevices: return true
|
||||
}
|
||||
}
|
||||
|
||||
/// - Returns: `true` iff SK2 is enabled and it's available.
|
||||
var shouldOnlyUseStoreKit2: Bool {
|
||||
switch self {
|
||||
|
||||
@@ -79,7 +79,7 @@ import Foundation
|
||||
private(set) var appUserID: String?
|
||||
private(set) var observerMode: Bool = false
|
||||
private(set) var userDefaults: UserDefaults?
|
||||
private(set) var storeKit2Setting: StoreKit2Setting = .init(useStoreKit2IfAvailable: false)
|
||||
private(set) var storeKit2Setting: StoreKit2Setting = .default
|
||||
private(set) var dangerousSettings: DangerousSettings?
|
||||
private(set) var networkTimeout = Configuration.networkTimeoutDefault
|
||||
private(set) var storeKit1Timeout = Configuration.storeKitRequestTimeoutDefault
|
||||
@@ -135,8 +135,8 @@ import Foundation
|
||||
|
||||
/**
|
||||
* Set `usesStoreKit2IfAvailable`.
|
||||
* - Parameter usesStoreKit2IfAvailable: opt in to using StoreKit 2 on devices that support it.
|
||||
* Purchases will be made using StoreKit 2 under the hood automatically.
|
||||
* - Parameter usesStoreKit2IfAvailable: opt out of using StoreKit 2 on devices that support it.
|
||||
* Defaults to `true`.
|
||||
*/
|
||||
@objc public func with(usesStoreKit2IfAvailable: Bool) -> Builder {
|
||||
self.storeKit2Setting = .init(useStoreKit2IfAvailable: usesStoreKit2IfAvailable)
|
||||
|
||||
@@ -18,6 +18,16 @@ import XCTest
|
||||
|
||||
class StoreKit2SettingTests: TestCase {
|
||||
|
||||
func testInitWithTrue() {
|
||||
expect(StoreKit2Setting(useStoreKit2IfAvailable: true)) == .enabledForCompatibleDevices
|
||||
expect(StoreKit2Setting(useStoreKit2IfAvailable: true).usesStoreKit2IfAvailable) == true
|
||||
}
|
||||
|
||||
func testInitWithFalse() {
|
||||
expect(StoreKit2Setting(useStoreKit2IfAvailable: false)) == .enabledOnlyForOptimizations
|
||||
expect(StoreKit2Setting(useStoreKit2IfAvailable: false).usesStoreKit2IfAvailable) == false
|
||||
}
|
||||
|
||||
func testStoreKit2NotAvailableWhenDisabled() {
|
||||
expect(StoreKit2Setting.disabled.shouldOnlyUseStoreKit2) == false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user