@@ -119,8 +119,8 @@ public class Amplitude {
119119
120120 let trackingQueue = DispatchQueue ( label: " com.amplitude.analytics " )
121121
122- private var diagnosticsObserverTask : Task < Void , Never > ?
123- private var diagnosticsObserverId : UUID ?
122+ private var enabledAutocapture : AutocaptureOptions = . init ( rawValue : 0 )
123+ private var needsSetAutocaptureDiagnostics : Bool = false
124124
125125 public init (
126126 configuration: Configuration
@@ -142,6 +142,7 @@ public class Amplitude {
142142 instanceName: configuration. getNormalizeInstanceName ( ) ,
143143 serverZone: serverZone,
144144 logger: configuration. loggerProvider,
145+ remoteConfigClient: configuration. remoteConfigClient,
145146 diagnosticsClient: configuration. diagnosticsClient)
146147
147148 let contextPlugin = ContextPlugin ( )
@@ -184,7 +185,10 @@ public class Amplitude {
184185 }
185186 trackingQueue. resume ( )
186187
187- setupDiagnosticsObserver ( )
188+ amplitudeContext. diagnosticsClient. setTag ( name: " sdk. \( Constants . SDK_LIBRARY) .version " , value: Constants . SDK_VERSION)
189+
190+ enabledAutocapture = configuration. autocapture
191+ updateDiagnosticsAutocaptureTags ( )
188192 }
189193
190194 convenience init ( apiKey: String , configuration: Configuration ) {
@@ -616,10 +620,6 @@ public class Amplitude {
616620 }
617621 logger? . debug ( message: " Completed trimming events, kept \( eventCount) most recent events " )
618622 }
619-
620- deinit {
621- diagnosticsObserverTask? . cancel ( )
622- }
623623}
624624
625625extension Amplitude : PluginHost {
@@ -655,45 +655,26 @@ extension Amplitude: AnalyticsClient {
655655 }
656656}
657657
658- // MARK: - Diagnostics
659-
660658extension Amplitude {
661659
662- private func setupDiagnosticsObserver( ) {
663- diagnosticsObserverTask = Task { [ weak self] in
664- guard let self else { return }
665-
666- let ( stream, observerId) = await self . amplitudeContext. diagnosticsClient. observeIsRunning ( )
667- self . diagnosticsObserverId = observerId
668-
669- for await isRunning in stream {
670- guard isRunning else { continue }
671- await self . setupDiagnostics ( )
672- await self . cleanupDiagnosticsObserver ( )
673- break
660+ func updateEnabledAutocapture( _ options: AutocaptureOptions , enabled: Bool ) {
661+ trackingQueue. async {
662+ if enabled {
663+ self . enabledAutocapture. formUnion ( options)
664+ } else {
665+ self . enabledAutocapture. subtract ( options)
674666 }
675- }
676- }
667+ self . needsSetAutocaptureDiagnostics = true
677668
678- private func cleanupDiagnosticsObserver( ) async {
679- if let observerId = diagnosticsObserverId {
680- await self . amplitudeContext. diagnosticsClient. stopObservingIsRunning ( observerId)
681- diagnosticsObserverId = nil
669+ self . trackingQueue. async { [ weak self] in
670+ guard let self, needsSetAutocaptureDiagnostics else { return }
671+ needsSetAutocaptureDiagnostics = false
672+ updateDiagnosticsAutocaptureTags ( )
673+ }
682674 }
683- diagnosticsObserverTask? . cancel ( )
684- diagnosticsObserverTask = nil
685675 }
686676
687- private func setupDiagnostics( ) async {
688- await amplitudeContext. diagnosticsClient. setTag ( name: " sdk. \( Constants . SDK_LIBRARY) .version " , value: Constants . SDK_VERSION)
689-
690- CrashCatcher . register ( )
691-
692- if let crash = CrashCatcher . checkForPreviousCrash ( ) {
693- CrashCatcher . clearCrashReport ( )
694- await amplitudeContext. diagnosticsClient. increment ( name: " analytics.crash " )
695- let eventProperties = [ " report " : crash]
696- await amplitudeContext. diagnosticsClient. recordEvent ( name: " analytics.crash " , properties: eventProperties)
697- }
677+ func updateDiagnosticsAutocaptureTags( ) {
678+ amplitudeContext. diagnosticsClient. setTag ( name: " autocapture.enabled " , value: enabledAutocapture. stringRepresentation ( ) )
698679 }
699680}
0 commit comments