Browse Source

Adapt diagnostics behavior to utilize Crashlytics

Deniz Cengiz 1 year ago
parent
commit
19aeaadff4

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

@@ -14,12 +14,12 @@ class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject, UNUserNoti
         let userDefaults = UserDefaults.standard
         // Default to `true` if the key doesn't exist
         let crashReportingEnabled: Bool = userDefaults.getValue(Bool.self, forKey: "DiagnosticsSharing") ?? 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
         // to boot after a crash
         Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(crashReportingEnabled)
-        
+
         return true
     }
 

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

@@ -1,3 +1,4 @@
+import FirebaseCrashlytics
 import Observation
 import SwiftUI
 
@@ -24,6 +25,7 @@ extension AppDiagnostics {
         func applyDiagnostics() {
             let booleanValue: Bool = diagnosticsSharingOption == .enabled
             UserDefaults.standard.set(booleanValue, forKey: "DiagnosticsSharing")
+            Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(booleanValue)
         }
     }
 }

+ 2 - 0
Trio/Sources/Modules/Onboarding/OnboardingStateModel.swift

@@ -1,4 +1,5 @@
 import Combine
+import FirebaseCrashlytics
 import Foundation
 import LoopKit
 import Observation
@@ -401,6 +402,7 @@ extension Onboarding {
         func applyDiagnostics() {
             let booleanValue: Bool = diagnosticsSharingOption == .enabled
             UserDefaults.standard.set(booleanValue, forKey: "DiagnosticsSharing")
+            Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(booleanValue)
         }
 
         /// Applies the selected glucose units to the app's settings.