diff --git a/Passepartout.xcodeproj/xcshareddata/xcschemes/Passepartout.xcscheme b/Passepartout.xcodeproj/xcshareddata/xcschemes/Passepartout.xcscheme index 47751167..bd8b23a9 100644 --- a/Passepartout.xcodeproj/xcshareddata/xcschemes/Passepartout.xcscheme +++ b/Passepartout.xcodeproj/xcshareddata/xcschemes/Passepartout.xcscheme @@ -172,7 +172,7 @@ - let buildProducts: BuildProducts let didRefundProducts = PassthroughSubject() @@ -95,10 +91,7 @@ final class ProductManager: NSObject, ObservableObject { init(overriddenAppType: AppType?, buildProducts: BuildProducts) { self.overriddenAppType = overriddenAppType self.buildProducts = buildProducts - appType = .undefined - sandboxChecker = SandboxChecker(bundle: .main) - subscriptions = [] products = [] inApp = InApp() @@ -113,18 +106,12 @@ final class ProductManager: NSObject, ObservableObject { SKPaymentQueue.default().add(self) refreshProducts() - sandboxChecker.$isBeta - .dropFirst() // ignore initial value - .sink { [weak self] in - guard let self else { - return - } - self.appType = overriddenAppType ?? ($0 ? .beta : .freemium) - pp_log.info("App type: \(self.appType)") - self.reloadReceipt() - }.store(in: &subscriptions) - - sandboxChecker.check() + Task { + let isBeta = await SandboxChecker().isBeta + appType = overriddenAppType ?? (isBeta ? .beta : .freemium) + pp_log.info("App type: \(appType)") + reloadReceipt() + } } deinit { diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Reusable/SandboxChecker.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Reusable/SandboxChecker.swift index 8dbb5e4a..eb6902d6 100644 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Reusable/SandboxChecker.swift +++ b/PassepartoutLibrary/Sources/PassepartoutCore/Reusable/SandboxChecker.swift @@ -28,25 +28,23 @@ import Foundation // https://stackoverflow.com/a/32238344/784615 // https://gist.github.com/lukaskubanek/cbfcab29c0c93e0e9e0a16ab09586996 -public final class SandboxChecker: ObservableObject { - private let bundle: Bundle - - @Published public private(set) var isBeta = false - - public init(bundle: Bundle) { - self.bundle = bundle +public final actor SandboxChecker: ObservableObject { + public init() { } - @MainActor - public func check() { - Task { - isBeta = await isBetaBuild() - pp_log.info("Beta build: \(isBeta)") - } + public var isBeta: Bool { + let isBeta = verifyBetaBuild() + pp_log.info("Beta build: \(isBeta)") + return isBeta } +} + +// MARK: Shared + +private extension SandboxChecker { // IMPORTANT: check Mac first because os(iOS) holds true for Catalyst - private func isBetaBuild() async -> Bool { + func verifyBetaBuild() -> Bool { #if targetEnvironment(macCatalyst) || os(macOS) isMacTestFlightBuild #elseif os(iOS) @@ -55,6 +53,10 @@ public final class SandboxChecker: ObservableObject { false #endif } + + var bundle: Bundle { + .main + } } // MARK: iOS @@ -70,8 +72,6 @@ private extension SandboxChecker { // MARK: macOS #if targetEnvironment(macCatalyst) || os(macOS) -import Security - private extension SandboxChecker { var isMacTestFlightBuild: Bool { var status = noErr