From 298ad297e81e0bf3f6311aa6b23d1ba545883894 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 3 Mar 2025 12:23:03 +0100 Subject: [PATCH] Adds refresh of purchases when opening the app --- PadelClub/AppDelegate.swift | 2 ++ PadelClub/Data/DataStore.swift | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/PadelClub/AppDelegate.swift b/PadelClub/AppDelegate.swift index e3d9e73..22383c0 100644 --- a/PadelClub/AppDelegate.swift +++ b/PadelClub/AppDelegate.swift @@ -24,6 +24,8 @@ class AppDelegate : NSObject, UIApplicationDelegate, UNUserNotificationCenterDel return true } + // MARK: - Remote Notifications + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { if StoreCenter.main.hasToken() { diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index b83f56d..e865413 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -98,7 +98,12 @@ class DataStore: ObservableObject { NotificationCenter.default.addObserver(self, selector: #selector(collectionDidLoad), name: NSNotification.Name.CollectionDidLoad, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(collectionDidUpdate), name: NSNotification.Name.CollectionDidChange, object: nil) - + NotificationCenter.default.addObserver( + self, + selector: #selector(_willEnterForegroundNotification), + name: UIScene.willEnterForegroundNotification, + object: nil) + } deinit { @@ -169,6 +174,12 @@ class DataStore: ObservableObject { self.objectWillChange.send() } + @objc func _willEnterForegroundNotification() { + Task { + try await self.purchases.loadDataFromServerIfAllowed(clear: true) + } + } + func disconnect() { Task {