From adbc086061ee96404cd44268bc22c760c06749d5 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 19 Apr 2022 14:32:15 +0200 Subject: [PATCH] Adjust eligibility conditionals to Catalyst - Replace os(iOS) with targetEnvironment(macCatalyst) - Reuse same beta condition on Catalyst (must test to confirm) --- .../Constants/Constants+Extensions.swift | 17 ++++++---------- .../App/Shared/InApp/ProductManager.swift | 20 +++++++++---------- .../App/iOS/Views/PaywallView+Purchase.swift | 12 +++++------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/Passepartout/App/Shared/Constants/Constants+Extensions.swift b/Passepartout/App/Shared/Constants/Constants+Extensions.swift index 05a8a68c..3027a759 100644 --- a/Passepartout/App/Shared/Constants/Constants+Extensions.swift +++ b/Passepartout/App/Shared/Constants/Constants+Extensions.swift @@ -70,25 +70,20 @@ extension Constants { return isBeta ? .beta : .freemium } - #if os(iOS) - static let lastFullVersionBuild: (Int, LocalProduct) = (2016, .fullVersion_iOS) - #else + #if targetEnvironment(macCatalyst) static let lastFullVersionBuild: (Int, LocalProduct) = (0, .fullVersion_macOS) + #else + static let lastFullVersionBuild: (Int, LocalProduct) = (2016, .fullVersion_iOS) #endif static let lastNetworkSettingsBuild = 2999 private static var isBeta: Bool { - #if os(iOS) #if targetEnvironment(simulator) return true #else return Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" #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 { - #if os(iOS) - static let eventCount = 3 - #else + #if targetEnvironment(macCatalyst) static let eventCount = 10 + #else + static let eventCount = 3 #endif } } diff --git a/Passepartout/App/Shared/InApp/ProductManager.swift b/Passepartout/App/Shared/InApp/ProductManager.swift index d6f48a2e..7ecb37b0 100644 --- a/Passepartout/App/Shared/InApp/ProductManager.swift +++ b/Passepartout/App/Shared/InApp/ProductManager.swift @@ -183,10 +183,10 @@ class ProductManager: NSObject, ObservableObject { // MARK: In-app eligibility private func isCurrentPlatformVersion() -> Bool { - #if os(iOS) - return purchasedFeatures.contains(.fullVersion_iOS) - #else + #if targetEnvironment(macCatalyst) return purchasedFeatures.contains(.fullVersion_macOS) + #else + return purchasedFeatures.contains(.fullVersion_iOS) #endif } @@ -206,10 +206,10 @@ class ProductManager: NSObject, ObservableObject { return true } } - #if os(iOS) - return isFullVersion() || purchasedFeatures.contains(feature) - #else + #if targetEnvironment(macCatalyst) return isFullVersion() + #else + return isFullVersion() || purchasedFeatures.contains(feature) #endif } @@ -299,12 +299,12 @@ extension ProductManager { let hasCancelledFullVersion: Bool let hasCancelledTrustedNetworks: Bool - #if os(iOS) - hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_iOS)) - hasCancelledTrustedNetworks = !isEligibleForFullVersion && isCancelledPurchase(.trustedNetworks) - #else + #if targetEnvironment(macCatalyst) hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_macOS)) hasCancelledTrustedNetworks = false + #else + hasCancelledFullVersion = !isEligibleForFullVersion && (isCancelledPurchase(.fullVersion) || isCancelledPurchase(.fullVersion_iOS)) + hasCancelledTrustedNetworks = !isEligibleForFullVersion && isCancelledPurchase(.trustedNetworks) #endif // review features and potentially revert them if they were used (Siri is handled in AppDelegate) diff --git a/Passepartout/App/iOS/Views/PaywallView+Purchase.swift b/Passepartout/App/iOS/Views/PaywallView+Purchase.swift index 41029ca5..118c6efa 100644 --- a/Passepartout/App/iOS/Views/PaywallView+Purchase.swift +++ b/Passepartout/App/iOS/Views/PaywallView+Purchase.swift @@ -189,21 +189,21 @@ extension PaywallView.PurchaseView { } private var skPlatformVersion: SKProduct? { - #if os(iOS) - return productManager.product(withIdentifier: .fullVersion_iOS) - #else + #if targetEnvironment(macCatalyst) return productManager.product(withIdentifier: .fullVersion_macOS) + #else + return productManager.product(withIdentifier: .fullVersion_iOS) #endif } // hide full version if already bought the other platform version private var skFullVersion: SKProduct? { - #if os(iOS) - guard !productManager.hasPurchased(.fullVersion_macOS) else { + #if targetEnvironment(macCatalyst) + guard !productManager.hasPurchased(.fullVersion_iOS) else { return nil } #else - guard !productManager.hasPurchased(.fullVersion_iOS) else { + guard !productManager.hasPurchased(.fullVersion_macOS) else { return nil } #endif