-
Notifications
You must be signed in to change notification settings - Fork 316
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
[SK2] Add Configuration.with(storeKitVersion:)
to select the version of StoreKit to use
#3487
Changes from 5 commits
4886d77
cb88d35
a98060c
49a3517
e06da0c
bfac38d
252093f
89a68b9
9e1ab81
b5a2efb
bc0561e
4430da5
323e366
d8b5f76
8f0b5ab
0c642d4
871e787
d4f683e
67abfbd
96b81cf
8a8a4ab
4f72f4d
0e854bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||
// | ||||||||
// 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 | ||||||||
// | ||||||||
// StoreKitVersion.swift | ||||||||
// | ||||||||
// Created by Mark Villacampa on 4/13/23. | ||||||||
|
||||||||
import Foundation | ||||||||
|
||||||||
/// Defines which version of StoreKit may be used | ||||||||
@objc(RCStoreKitVersion) | ||||||||
public enum StoreKitVersion: Int { | ||||||||
NachoSoto marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this to have a
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Setting explicit values 👍 |
||||||||
|
||||||||
/// Always use StoreKit 1. StoreKit 2 will be used (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 storeKit1 | ||||||||
|
||||||||
/// Always use StoreKit 2. | ||||||||
case storeKit2 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit spacing below
Suggested change
|
||||||||
|
||||||||
/// Let RevenueCat use the most appropiate version of StoreKit | ||||||||
case `default` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of making this a
Since it's technically not a different version. Then we don't need to consider it separately in all the logic, and to update it we only need to change it in one place. |
||||||||
} | ||||||||
|
||||||||
extension StoreKitVersion { | ||||||||
|
||||||||
/// - Returns: `true` if SK2 is available in this device. | ||||||||
static var isStoreKit2Available: Bool { | ||||||||
if #available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *) { | ||||||||
return true | ||||||||
} else { | ||||||||
return false | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
/// - Returns: `true` if and only if SK2 is enabled and it's available. | ||||||||
var isStoreKit2EnabledAndAvailable: Bool { | ||||||||
switch self { | ||||||||
case .storeKit1, .default: return false | ||||||||
case .storeKit2: return Self.isStoreKit2Available | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
} | ||||||||
|
||||||||
extension StoreKitVersion { | ||||||||
|
||||||||
var versionString: String { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: spacing here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: putting the type of the value in the name isn't a thing anymore 😅 Maybe we can do this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Objc throwback 🤣 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed it to |
||||||||
if self.isStoreKit2EnabledAndAvailable { | ||||||||
return "2" | ||||||||
} else { | ||||||||
return "1" | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ import Foundation | |
let observerMode: Bool | ||
let userDefaults: UserDefaults? | ||
let storeKit2Setting: StoreKit2Setting | ||
let storeKitVersion: StoreKitVersion | ||
let dangerousSettings: DangerousSettings? | ||
let networkTimeout: TimeInterval | ||
let storeKit1Timeout: TimeInterval | ||
|
@@ -61,6 +62,7 @@ import Foundation | |
self.observerMode = builder.observerMode | ||
self.userDefaults = builder.userDefaults | ||
self.storeKit2Setting = builder.storeKit2Setting | ||
self.storeKitVersion = builder.storeKitVersion | ||
self.dangerousSettings = builder.dangerousSettings | ||
self.storeKit1Timeout = builder.storeKit1Timeout | ||
self.networkTimeout = builder.networkTimeout | ||
|
@@ -92,6 +94,7 @@ import Foundation | |
private(set) var platformInfo: Purchases.PlatformInfo? | ||
private(set) var responseVerificationMode: Signing.ResponseVerificationMode = .default | ||
private(set) var showStoreMessagesAutomatically: Bool = true | ||
private(set) var storeKitVersion: StoreKitVersion = .default | ||
|
||
/** | ||
* Create a new builder with your API key. | ||
|
@@ -218,6 +221,27 @@ import Foundation | |
return self | ||
} | ||
|
||
/// Set ``StoreKitVersion``. | ||
/// | ||
/// Defaults to ``StoreKitVersion/default`` which lets the SDK select | ||
/// the most appropriate version of StoreKit. Currently defaults to StoreKit 1. | ||
/// | ||
/// - Note: StoreKit 2 is only available on iOS 15+. StoreKit 1 will be used for previous iOS versions | ||
/// regardless of this setting. | ||
/// | ||
/// ### Related Symbols | ||
/// - ``StoreKitVersion`` | ||
@objc public func with(storeKitVersion version: StoreKitVersion) -> Builder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started doing this for #3066 but ended up removing it. I think it's a better API 👍🏻 |
||
self.storeKitVersion = version | ||
switch version { | ||
case .storeKit1, .default: | ||
self.storeKit2Setting = .init(useStoreKit2IfAvailable: false) | ||
case .storeKit2: | ||
self.storeKit2Setting = .init(useStoreKit2IfAvailable: true) | ||
} | ||
return self | ||
} | ||
|
||
/// Generate a ``Configuration`` object given the values configured by this builder. | ||
@objc public func build() -> Configuration { | ||
return Configuration(with: self) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ @implementation RCConfigurationAPI | |
|
||
+ (void)checkAPI { | ||
RCConfigurationBuilder *builder = [RCConfiguration builderWithAPIKey:@""]; | ||
RCConfiguration *config __unused = [[[[[[[[[[[builder withApiKey:@""] | ||
RCConfiguration *config __unused = [[[[[[[[[[[[builder withApiKey:@""] | ||
withObserverMode:false] | ||
withUserDefaults:NSUserDefaults.standardUserDefaults] | ||
withAppUserID:@""] | ||
|
@@ -23,6 +23,7 @@ + (void)checkAPI { | |
withStoreKit1Timeout: 1] | ||
withPlatformInfo:[[RCPlatformInfo alloc] initWithFlavor:@"" version:@""]] | ||
withUsesStoreKit2IfAvailable:false] | ||
withStoreKitVersion:RCStoreKitVersionStoreKit2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also add tests (Swift + Obj-C) for the enum with the 2 cases + default. |
||
build]; | ||
|
||
if (@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
String
could be anything. Better to useStoreKitVersion
to make it type safe.