From 7f0fd119c5df56ce6e678a12c54a45cc0321af63 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 3 Jul 2020 18:45:37 -0400 Subject: [PATCH] Use App Group for user defaults --- Tusker/LocalData.swift | 15 ++++++++++++++- Tusker/Tusker.entitlements | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Tusker/LocalData.swift b/Tusker/LocalData.swift index 821b3955..5c9f51e0 100644 --- a/Tusker/LocalData.swift +++ b/Tusker/LocalData.swift @@ -30,7 +30,20 @@ class LocalData: ObservableObject { ] } } else { - defaults = UserDefaults() + defaults = UserDefaults(suiteName: "group.space.vaccor.Tusker")! + tryMigrateOldDefaults() + } + } + + // TODO: remove me before public beta + private func tryMigrateOldDefaults() { + let old = UserDefaults() + if let accounts = old.array(forKey: accountsKey) as? [[String: String]], + let mostRecentAccount = old.string(forKey: mostRecentAccountKey) { + defaults.setValue(accounts, forKey: accountsKey) + defaults.setValue(mostRecentAccount, forKey: mostRecentAccountKey) + old.removeObject(forKey: accountsKey) + old.removeObject(forKey: mostRecentAccountKey) } } diff --git a/Tusker/Tusker.entitlements b/Tusker/Tusker.entitlements index 13ce7b19..ad0d7a74 100644 --- a/Tusker/Tusker.entitlements +++ b/Tusker/Tusker.entitlements @@ -4,6 +4,10 @@ com.apple.security.app-sandbox + com.apple.security.application-groups + + group.space.vaccor.Tusker + com.apple.security.device.audio-input com.apple.security.device.camera