Explorar o código

Merge pull request #496 from nightscout/move-diagnostic-setting-to-plist

Moves the App Diagnostics setting to a plist
Deniz Cengiz hai 1 ano
pai
achega
bd7885e0cd

+ 1 - 2
Trio/Sources/Application/AppDelegate.swift

@@ -11,9 +11,8 @@ class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject, UNUserNoti
     ) -> Bool {
         FirebaseApp.configure()
 
-        let userDefaults = UserDefaults.standard
         // Default to `true` if the key doesn't exist
-        let crashReportingEnabled: Bool = userDefaults.getValue(Bool.self, forKey: "DiagnosticsSharing") ?? true
+        let crashReportingEnabled: Bool = PropertyPersistentFlags.shared.diagnosticsSharingEnabled ?? true
 
         // The docs say that changes to this don't take effect until
         // the next app boot, but this is fine since the app will need

+ 2 - 2
Trio/Sources/Modules/AppDiagnostics/AppDiagnosticsStateModel.swift

@@ -14,7 +14,7 @@ extension AppDiagnostics {
 
         /// Loads the diagnostics sharing option from UserDefaults as a boolean.
         func loadDiagnostics() {
-            if let storedDiagnosticsSharingOption = UserDefaults.standard.value(forKey: "DiagnosticsSharing") as? Bool {
+            if let storedDiagnosticsSharingOption = PropertyPersistentFlags.shared.diagnosticsSharingEnabled {
                 diagnosticsSharingOption = storedDiagnosticsSharingOption ? .enabled : .disabled
             } else {
                 diagnosticsSharingOption = .enabled
@@ -24,7 +24,7 @@ extension AppDiagnostics {
         /// Persists the current diagnostics sharing option to UserDefaults as a boolean.
         func applyDiagnostics() {
             let booleanValue: Bool = diagnosticsSharingOption == .enabled
-            UserDefaults.standard.set(booleanValue, forKey: "DiagnosticsSharing")
+            PropertyPersistentFlags.shared.diagnosticsSharingEnabled = booleanValue
             Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(booleanValue)
         }
     }