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 {