Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate usesStoreKit2IfAvailable #2293

Merged
merged 8 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion Sources/Misc/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import Foundation
import StoreKit

// swiftlint:disable line_length missing_docs
// swiftlint:disable line_length missing_docs file_length

public extension Purchases {

Expand Down Expand Up @@ -389,3 +389,29 @@ extension CustomerInfo {
}

}

public extension Configuration.Builder {

/// Set `usesStoreKit2IfAvailable`. If `true`, the SDK will use StoreKit 2 APIs internally. If disabled, it will use StoreKit 1 APIs instead.
/// - Parameter usesStoreKit2IfAvailable: enable StoreKit 2 on devices that support it.
/// Defaults to `false`.
/// - Important: This configuration flag has been deprecated, and will be replaced by automatic remote configuration in the future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what you mean by "automatic remote configuration"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm well, this might be going too ahead with this comment, but I believe the intention is to support changing this dynamically from the backend. So we could decide, according to the status returned by diagnostics or other sources, change whether apps use SK1 or SK2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh that makes sense

/// However, apps using it should work correctly.
///
@available(*, deprecated, message: """
RevenueCat currently uses StoreKit 1 for purchases, as its stability in production scenarios has
proven to be more performant than StoreKit 2.

We're collecting more data on the best approach, but StoreKit 1 vs StoreKit 2 is an implementation detail
that you shouldn't need to care about.

Simply remove this method call to let RevenueCat decide for you which StoreKit implementation to use.
""")
@objc func with(usesStoreKit2IfAvailable: Bool) -> Configuration.Builder {
self.storeKit2Setting = .init(useStoreKit2IfAvailable: usesStoreKit2IfAvailable)
return self
}

}

// swiftlint:enable line_length missing_docs file_length
15 changes: 3 additions & 12 deletions Sources/Purchasing/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Foundation
* .with(userDefaults: myUserDefaults)
* .with(networkTimeout: 15)
* .with(storeKit1Timeout: 15)
* .with(usesStoreKit2IfAvailable: true)
* .build()
* Purchases.configure(with: configuration)
* ```
Expand Down Expand Up @@ -75,13 +74,15 @@ import Foundation
/// The Builder for ```Configuration```.
@objc(RCConfigurationBuilder) public class Builder: NSObject {

// made internal to access it in Deprecations.swift
var storeKit2Setting: StoreKit2Setting = .default

private static let minimumTimeout: TimeInterval = 5

private(set) var apiKey: String
private(set) var appUserID: String?
private(set) var observerMode: Bool = false
private(set) var userDefaults: UserDefaults?
private(set) var storeKit2Setting: StoreKit2Setting = .default
private(set) var dangerousSettings: DangerousSettings?
private(set) var networkTimeout = Configuration.networkTimeoutDefault
private(set) var storeKit1Timeout = Configuration.storeKitRequestTimeoutDefault
Expand Down Expand Up @@ -136,16 +137,6 @@ import Foundation
return self
}

/**
* Set `usesStoreKit2IfAvailable`.
* - Parameter usesStoreKit2IfAvailable: opt in using StoreKit 2 on devices that support it.
* Defaults to `false`.
*/
@objc public func with(usesStoreKit2IfAvailable: Bool) -> Builder {
self.storeKit2Setting = .init(useStoreKit2IfAvailable: usesStoreKit2IfAvailable)
return self
}

/**
* Set `dangerousSettings`.
* - Parameter dangerousSettings: Only use if suggested by RevenueCat support team.
Expand Down
2 changes: 0 additions & 2 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,6 @@ public extension Purchases {
* ```swift
* Purchases.configure(
* with: Configuration.Builder(withAPIKey: Constants.apiKey)
* .with(usesStoreKit2IfAvailable: true)
* .with(observerMode: false)
* .with(appUserID: "<app_user_id>")
* .build()
Expand Down Expand Up @@ -933,7 +932,6 @@ public extension Purchases {
* ```swift
* Purchases.configure(
* with: .init(withAPIKey: Constants.apiKey)
* .with(usesStoreKit2IfAvailable: true)
* .with(observerMode: false)
* .with(appUserID: "<app_user_id>")
* )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func checkConfigurationAPI() {
.with(dangerousSettings: DangerousSettings())
.with(networkTimeout: 1)
.with(storeKit1Timeout: 1)
.with(usesStoreKit2IfAvailable: false)
.with(platformInfo: Purchases.PlatformInfo(flavor: "", version: ""))
.build()
print(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class PurchasesConfiguringTests: BasePurchasesTests {
expect(self.storeKit1Wrapper.delegate) === self.purchasesOrchestrator
}

@available(*, deprecated) // Ignore deprecation warnings
func testSetsSelfAsStoreKit1WrapperDelegateForSK1() {
let configurationBuilder = Configuration.Builder(withAPIKey: "")
.with(usesStoreKit2IfAvailable: false)
Expand All @@ -332,6 +333,7 @@ class PurchasesConfiguringTests: BasePurchasesTests {
expect(purchases.isStoreKit1Configured) == true
}

@available(*, deprecated) // Ignore deprecation warnings
func testDoesNotInitializeSK1IfSK2Enabled() throws {
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()

Expand Down