Skip to content

Commit

Permalink
fix: prevent main thread checker warning (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
crleona authored Nov 18, 2024
1 parent 700637b commit 7b71d12
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class IOSLifecycleMonitor: UtilityPlugin {
utils = DefaultEventUtils(amplitude: amplitude)

// If we are already in the foreground, dispatch installed / opened events now
if IOSVendorSystem.sharedApplication?.applicationState == .active {
// Use keypath vs applicationState property to avoid main thread checker warning,
// we want to dispatch this from the initiating thread to maintain event ordering.
if let application = IOSVendorSystem.sharedApplication,
let rawState = application.value(forKey: #keyPath(UIApplication.applicationState)) as? Int,
let applicationState = UIApplication.State(rawValue: rawState),
applicationState == .active {
utils?.trackAppUpdatedInstalledEvent()
amplitude.onEnterForeground(timestamp: currentTimestamp)
utils?.trackAppOpenedEvent()
Expand Down

0 comments on commit 7b71d12

Please sign in to comment.