From c45af32163ced206068df1862b2cd40431c835c5 Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sun, 5 May 2024 00:05:41 +0400 Subject: [PATCH] Reduced compilation duration --- Sources/Segment/Plugins/Context.swift | 8 +++- .../Platforms/iOS/iOSLifecycleEvents.swift | 45 ++++++++++--------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Sources/Segment/Plugins/Context.swift b/Sources/Segment/Plugins/Context.swift index 3590a625..a0f98ead 100644 --- a/Sources/Segment/Plugins/Context.swift +++ b/Sources/Segment/Plugins/Context.swift @@ -72,8 +72,14 @@ public class Context: PlatformPlugin { app.merge(localizedInfo) { (_, new) in new } } if app.count != 0 { + var name: String = "" + if let displayName = app["CFBundleDisplayName"] as? String { + name = displayName + } else if let displayName = app["CFBundleName"] as? String { + name = displayName + } staticContext["app"] = [ - "name": app["CFBundleDisplayName"] ?? app["CFBundleName"] ?? "" , + "name": name, "version": app["CFBundleShortVersionString"] ?? "", "build": app["CFBundleVersion"] ?? "", "namespace": Bundle.main.bundleIdentifier ?? "" diff --git a/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift b/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift index dd26beee..edfb91d7 100644 --- a/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift +++ b/Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift @@ -34,35 +34,36 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle { return } - let previousVersion = UserDefaults.standard.string(forKey: Self.versionKey) - let previousBuild = UserDefaults.standard.string(forKey: Self.buildKey) - - let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String - let currentBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String - - if previousBuild == nil { - analytics?.track(name: "Application Installed", properties: [ - "version": currentVersion ?? "", - "build": currentBuild ?? "" - ]) - } else if currentBuild != previousBuild { + let previousVersion: String? = UserDefaults.standard.string(forKey: Self.versionKey) + let previousBuild: String? = UserDefaults.standard.string(forKey: Self.buildKey) + + let currentVersion: String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" + let currentBuild: String = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "" + + if let previousBuild, + currentBuild != previousBuild { analytics?.track(name: "Application Updated", properties: [ "previous_version": previousVersion ?? "", - "previous_build": previousBuild ?? "", - "version": currentVersion ?? "", - "build": currentBuild ?? "" + "previous_build": previousBuild, + "version": currentVersion, + "build": currentBuild + ]) + } else { + analytics?.track(name: "Application Installed", properties: [ + "version": currentVersion, + "build": currentBuild ]) } - - let sourceApp: String? = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? "" - let url: String? = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? "" + + let sourceApp: String = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? "" + let url: String = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? "" analytics?.track(name: "Application Opened", properties: [ "from_background": false, - "version": currentVersion ?? "", - "build": currentBuild ?? "", - "referring_application": sourceApp ?? "", - "url": url ?? "" + "version": currentVersion, + "build": currentBuild, + "referring_application": sourceApp, + "url": url ]) UserDefaults.standard.setValue(currentVersion, forKey: Self.versionKey)