Adjust eligibility conditionals to Catalyst

- Replace os(iOS) with targetEnvironment(macCatalyst)

- Reuse same beta condition on Catalyst (must test to confirm)
This commit is contained in:
Davide De Rosa 2022-04-19 14:32:15 +02:00
parent f1aa192c9c
commit adbc086061
3 changed files with 22 additions and 27 deletions

View File

@ -70,25 +70,20 @@ extension Constants {
return isBeta ? .beta : .freemium return isBeta ? .beta : .freemium
} }
#if os(iOS) #if targetEnvironment(macCatalyst)
static let lastFullVersionBuild: (Int, LocalProduct) = (2016, .fullVersion_iOS)
#else
static let lastFullVersionBuild: (Int, LocalProduct) = (0, .fullVersion_macOS) static let lastFullVersionBuild: (Int, LocalProduct) = (0, .fullVersion_macOS)
#else
static let lastFullVersionBuild: (Int, LocalProduct) = (2016, .fullVersion_iOS)
#endif #endif
static let lastNetworkSettingsBuild = 2999 static let lastNetworkSettingsBuild = 2999
private static var isBeta: Bool { private static var isBeta: Bool {
#if os(iOS)
#if targetEnvironment(simulator) #if targetEnvironment(simulator)
return true return true
#else #else
return Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" return Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
#endif #endif
#else
// TODO: production, skip TestFlight on macOS until beta condition is clearly determined
return false
#endif
} }
} }
} }
@ -256,10 +251,10 @@ extension Constants {
} }
enum Rating { enum Rating {
#if os(iOS) #if targetEnvironment(macCatalyst)
static let eventCount = 3
#else
static let eventCount = 10 static let eventCount = 10
#else
static let eventCount = 3
#endif #endif
} }
} }

View File

@ -183,10 +183,10 @@ class ProductManager: NSObject, ObservableObject {
// MARK: In-app eligibility // MARK: In-app eligibility
private func isCurrentPlatformVersion() -> Bool { private func isCurrentPlatformVersion() -> Bool {
#if os(iOS) #if targetEnvironment(macCatalyst)
return purchasedFeatures.contains(.fullVersion_iOS)
#else
return purchasedFeatures.contains(.fullVersion_macOS) return purchasedFeatures.contains(.fullVersion_macOS)
#else
return purchasedFeatures.contains(.fullVersion_iOS)
#endif #endif
} }
@ -206,10 +206,10 @@ class ProductManager: NSObject, ObservableObject {
return true return true
} }
} }
#if os(iOS) #if targetEnvironment(macCatalyst)
return isFullVersion() || purchasedFeatures.contains(feature)
#else
return isFullVersion() return isFullVersion()
#else
return isFullVersion() || purchasedFeatures.contains(feature)
#endif #endif
} }
@ -299,12 +299,12 @@ extension ProductManager {
let hasCancelledFullVersion: Bool let hasCancelledFullVersion: Bool
let hasCancelledTrustedNetworks: Bool let hasCancelledTrustedNetworks: Bool
#if os(iOS) #if targetEnvironment(macCatalyst)
hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_iOS))
hasCancelledTrustedNetworks = !isEligibleForFullVersion && isCancelledPurchase(.trustedNetworks)
#else
hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_macOS)) hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_macOS))
hasCancelledTrustedNetworks = false hasCancelledTrustedNetworks = false
#else
hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_iOS))
hasCancelledTrustedNetworks = !isEligibleForFullVersion && isCancelledPurchase(.trustedNetworks)
#endif #endif
// review features and potentially revert them if they were used (Siri is handled in AppDelegate) // review features and potentially revert them if they were used (Siri is handled in AppDelegate)

View File

@ -189,21 +189,21 @@ extension PaywallView.PurchaseView {
} }
private var skPlatformVersion: SKProduct? { private var skPlatformVersion: SKProduct? {
#if os(iOS) #if targetEnvironment(macCatalyst)
return productManager.product(withIdentifier: .fullVersion_iOS)
#else
return productManager.product(withIdentifier: .fullVersion_macOS) return productManager.product(withIdentifier: .fullVersion_macOS)
#else
return productManager.product(withIdentifier: .fullVersion_iOS)
#endif #endif
} }
// hide full version if already bought the other platform version // hide full version if already bought the other platform version
private var skFullVersion: SKProduct? { private var skFullVersion: SKProduct? {
#if os(iOS) #if targetEnvironment(macCatalyst)
guard !productManager.hasPurchased(.fullVersion_macOS) else { guard !productManager.hasPurchased(.fullVersion_iOS) else {
return nil return nil
} }
#else #else
guard !productManager.hasPurchased(.fullVersion_iOS) else { guard !productManager.hasPurchased(.fullVersion_macOS) else {
return nil return nil
} }
#endif #endif