From f9c5c42290c12a9187d3c485fd42f9cde42e9836 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 26 Jun 2024 11:24:14 -0700 Subject: [PATCH] load preferences --- .../ios/ExpoBackgroundNotificationHandlerModule.swift | 5 +++++ .../src/BackgroundNotificationHandlerProvider.tsx | 4 +++- modules/expo-background-notification-handler/src/index.ts | 2 +- .../ios/SharedPrefs/SharedPrefs.swift | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift b/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift index 66fe6b6783..a19bc05a3e 100644 --- a/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift +++ b/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift @@ -64,6 +64,11 @@ public class ExpoBackgroundNotificationHandlerModule: Module { SharedPrefs.shared.removeFromSet(INCREMENTED_FOR_KEY, convoId) SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count) } + + AsyncFunction("getPrefsAsync") { + let keys = Array(DEFAULTS.keys) + return SharedPrefs.shared.getValues(keys) + } } } diff --git a/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx b/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx index 4307a61099..b943e24a0b 100644 --- a/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx +++ b/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx @@ -31,7 +31,9 @@ export function BackgroundNotificationPreferencesProvider({ React.useEffect(() => { ;(async () => { const prefs = await BackgroundNotifications.getPrefsAsync() - setPreferences(prefs) + if (prefs) { + setPreferences(prefs) + } })() }, []) diff --git a/modules/expo-background-notification-handler/src/index.ts b/modules/expo-background-notification-handler/src/index.ts index a859c7ecea..918dc95f34 100644 --- a/modules/expo-background-notification-handler/src/index.ts +++ b/modules/expo-background-notification-handler/src/index.ts @@ -19,6 +19,6 @@ export function decrementMessagesCountAsync( throw new NotImplementedError({count, convoId}) } -export function getPrefsAsync(): Promise { +export function getPrefsAsync(): Promise { throw new NotImplementedError() } diff --git a/modules/expo-bluesky-swiss-army/ios/SharedPrefs/SharedPrefs.swift b/modules/expo-bluesky-swiss-army/ios/SharedPrefs/SharedPrefs.swift index e9858aba64..fc573f84a2 100644 --- a/modules/expo-bluesky-swiss-army/ios/SharedPrefs/SharedPrefs.swift +++ b/modules/expo-bluesky-swiss-army/ios/SharedPrefs/SharedPrefs.swift @@ -82,4 +82,8 @@ public class SharedPrefs { public func hasValue(_ key: String) -> Bool { return getDefaults(key)?.value(forKey: key) != nil } + + public func getValues(_ keys: [String]) -> [String:Any?]? { + return getDefaults("keys:\(keys)")?.dictionaryWithValues(forKeys: keys) + } }