From e1bd73f3279bd07e14f58c3d933121d4c2b435ec Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Mon, 6 Nov 2023 14:56:04 -0800 Subject: [PATCH] Tightened up application opened events to prevent duplicates (#267) --- .../Platforms/iOS/iOSLifecycleEvents.swift | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift b/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift index 93bfe1d2..64d99d1f 100644 --- a/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift +++ b/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift @@ -77,18 +77,20 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle { let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String let currentBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String - analytics?.track(name: "Application Opened", properties: [ - "from_background": true, - "version": currentVersion ?? "", - "build": currentBuild ?? "" - ]) + if didFinishLaunching == false { + analytics?.track(name: "Application Opened", properties: [ + "from_background": true, + "version": currentVersion ?? "", + "build": currentBuild ?? "" + ]) + } } func applicationDidEnterBackground(application: UIApplication?) { + didFinishLaunching = false if analytics?.configuration.values.trackApplicationLifecycleEvents == false { return } - analytics?.track(name: "Application Backgrounded") } @@ -96,15 +98,7 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle { if analytics?.configuration.values.trackApplicationLifecycleEvents == false { return } - analytics?.track(name: "Application Foregrounded") - - // Lets check if we skipped application:didFinishLaunchingWithOptions, - // if so, lets call it. - if didFinishLaunching == false { - // Call application did finish launching - self.application(nil, didFinishLaunchingWithOptions: nil) - } } }