Skip to content

Commit

Permalink
Tightened up application opened events to prevent duplicates (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed authored Nov 6, 2023
1 parent efc111b commit e1bd73f
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,28 @@ 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")
}

func applicationDidBecomeActive(application: UIApplication?) {
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)
}
}
}

Expand Down

0 comments on commit e1bd73f

Please sign in to comment.