diff --git a/PadelClub.xcodeproj/xcshareddata/xcschemes/PadelClub.xcscheme b/PadelClub.xcodeproj/xcshareddata/xcschemes/PadelClub.xcscheme index 1d7b355..c9495dd 100644 --- a/PadelClub.xcodeproj/xcshareddata/xcschemes/PadelClub.xcscheme +++ b/PadelClub.xcodeproj/xcshareddata/xcschemes/PadelClub.xcscheme @@ -74,7 +74,7 @@ + identifier = "../PadelClub/SyncedProducts.storekit"> Bool { // Override point for customization after application launch. + + _ = Guard.main // init guard + UIApplication.shared.registerForRemoteNotifications() UNUserNotificationCenter.current().delegate = self diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 2a05d74..d9d04ac 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -67,9 +67,7 @@ class DataStore: ObservableObject { StoreCenter.main.logsFailedAPICalls() var synchronized: Bool = true - - _ = Guard.main // init - + #if DEBUG if let sync = PListReader.readBool(plist: "local", key: "synchronized") { synchronized = sync diff --git a/PadelClub/Utils/URLs.swift b/PadelClub/Utils/URLs.swift index f83495b..beb49a7 100644 --- a/PadelClub/Utils/URLs.swift +++ b/PadelClub/Utils/URLs.swift @@ -9,9 +9,15 @@ import Foundation enum URLs: String, Identifiable { +#if DEBUG case activationHost = "xlr.alwaysdata.net" case main = "https://xlr.alwaysdata.net/" case api = "https://xlr.alwaysdata.net/roads/" +#else + case activationHost = "padelclub.app" + case main = "https://padelclub.app/" + case api = "https://padelclub.app/roads/" +#endif case subscriptions = "https://apple.co/2Th4vqI" case beachPadel = "https://beach-padel.app.fft.fr/beachja/index/" diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index ac79547..0740e0b 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -16,6 +16,7 @@ struct UmpireView: View { @State private var presentSearchView: Bool = false @State private var showSubscriptions: Bool = false + @State private var showProductIds: Bool = false // @State var isConnected: Bool = false @@ -36,7 +37,20 @@ struct UmpireView: View { self.showSubscriptions = true } label: { Label("Les offres", systemImage: "bookmark.fill") - } + }.simultaneousGesture( + LongPressGesture() + .onEnded { _ in + self.showProductIds = true + } + ) + + .highPriorityGesture( + TapGesture() + .onEnded { _ in + self.showSubscriptions = true + } + ) + } } @@ -161,6 +175,9 @@ struct UmpireView: View { .environment(\.colorScheme, .light) } }) + .sheet(isPresented: self.$showProductIds, content: { + ProductIdsView() + }) .sheet(isPresented: $presentSearchView) { let user = dataStore.user NavigationStack { @@ -228,6 +245,27 @@ struct AccountRowView: View { } } +struct ProductIdsView: View { + + @State var ids: [String] = [] + + var body: some View { + VStack { + List { + LabeledContent("count", value: String(ids.count)) + ForEach(self.ids) { id in + Text(id) + } + }.onAppear { + Task { + self.ids = await Guard.main.productIds() + } + } + } + } + +} + //#Preview { // UmpireView() //} diff --git a/PadelClub/Views/Tournament/Subscription/Guard.swift b/PadelClub/Views/Tournament/Subscription/Guard.swift index d0eec4e..8ff3df5 100644 --- a/PadelClub/Views/Tournament/Subscription/Guard.swift +++ b/PadelClub/Views/Tournament/Subscription/Guard.swift @@ -18,7 +18,7 @@ import LeStorage var currentBestPlan: StoreKit.Transaction? = nil - var updateListenerTask: Task? = nil + var updateListenerTask: Task? = nil fileprivate(set) var purchases: StoredCollection @@ -39,6 +39,23 @@ import LeStorage } } + deinit { + self.updateListenerTask?.cancel() + } + + func productIds() async -> [String] { + var productIds: [String] = [] + for await result in Transaction.all { + do { + let verified = try self.checkVerified(result) + productIds.append(verified.productID) + } catch { + Logger.error(error) + } + } + return productIds + } + func refreshPurchasedAppleProducts() async throws { // Iterate through the user's purchased products. @@ -51,10 +68,11 @@ import LeStorage } } - func listenForTransactions() -> Task { - return Task.detached { + func listenForTransactions() -> Task { + return Task(priority: .background) { //Iterate through any transactions which didn't come from a direct call to `purchase()`. for await result in Transaction.updates { + Logger.log(">>> update = \(result)") do { let transaction = try self.checkVerified(result) @@ -140,7 +158,14 @@ import LeStorage } var currentPlan: StoreItem? { - return .monthlyUnlimited + #if DEBUG + return .monthlyUnlimited + #else + if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { + return plan + } + return nil + #endif } func userFilteredPurchases() -> [StoreKit.Transaction] {