Skip to content

Commit 85ba59b

Browse files
committed
perform full flush before unregistering replay id
1 parent 61ce9b4 commit 85ba59b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Sources/MixpanelInstance.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
495495

496496
#if !os(OSX) && !os(watchOS)
497497
@objc private func applicationDidEnterBackground(_ notification: Notification) {
498+
performFullBackgroundFlush()
499+
}
500+
501+
private func performFullBackgroundFlush(propsToUnregister: InternalProperties? = nil) {
498502
guard let sharedApplication = MixpanelInstance.sharedUIApplication() else {
499503
return
500504
}
@@ -506,6 +510,12 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
506510
let completionHandler: () -> Void = { [weak self] in
507511
guard let self = self else { return }
508512

513+
if let propsToUnregister {
514+
for (key, _) in propsToUnregister {
515+
unregisterSuperProperty(key)
516+
}
517+
}
518+
509519
if self.taskId != UIBackgroundTaskIdentifier.invalid {
510520
sharedApplication.endBackgroundTask(self.taskId)
511521
self.taskId = UIBackgroundTaskIdentifier.invalid
@@ -653,11 +663,7 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
653663
guard let properties = data as? Properties else { return }
654664
registerSuperProperties(properties)
655665
} else {
656-
for (key, _) in data {
657-
if let keyToUnregister = key as? String {
658-
unregisterSuperProperty(keyToUnregister)
659-
}
660-
}
666+
performFullBackgroundFlush(propsToUnregister: data as? InternalProperties)
661667
}
662668
}
663669
}

0 commit comments

Comments
 (0)