Skip to content

Commit eded4ac

Browse files
authored
Reduced compilation duration (#340)
1 parent f6f3a7f commit eded4ac

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

Sources/Segment/Plugins/Context.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ public class Context: PlatformPlugin {
7272
app.merge(localizedInfo) { (_, new) in new }
7373
}
7474
if app.count != 0 {
75+
var name: String = ""
76+
if let displayName = app["CFBundleDisplayName"] as? String {
77+
name = displayName
78+
} else if let displayName = app["CFBundleName"] as? String {
79+
name = displayName
80+
}
7581
staticContext["app"] = [
76-
"name": app["CFBundleDisplayName"] ?? app["CFBundleName"] ?? "" ,
82+
"name": name,
7783
"version": app["CFBundleShortVersionString"] ?? "",
7884
"build": app["CFBundleVersion"] ?? "",
7985
"namespace": Bundle.main.bundleIdentifier ?? ""

Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,36 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle {
3434
return
3535
}
3636

37-
let previousVersion = UserDefaults.standard.string(forKey: Self.versionKey)
38-
let previousBuild = UserDefaults.standard.string(forKey: Self.buildKey)
39-
40-
let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
41-
let currentBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String
42-
43-
if previousBuild == nil {
44-
analytics?.track(name: "Application Installed", properties: [
45-
"version": currentVersion ?? "",
46-
"build": currentBuild ?? ""
47-
])
48-
} else if currentBuild != previousBuild {
37+
let previousVersion: String? = UserDefaults.standard.string(forKey: Self.versionKey)
38+
let previousBuild: String? = UserDefaults.standard.string(forKey: Self.buildKey)
39+
40+
let currentVersion: String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
41+
let currentBuild: String = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
42+
43+
if let previousBuild,
44+
currentBuild != previousBuild {
4945
analytics?.track(name: "Application Updated", properties: [
5046
"previous_version": previousVersion ?? "",
51-
"previous_build": previousBuild ?? "",
52-
"version": currentVersion ?? "",
53-
"build": currentBuild ?? ""
47+
"previous_build": previousBuild,
48+
"version": currentVersion,
49+
"build": currentBuild
50+
])
51+
} else {
52+
analytics?.track(name: "Application Installed", properties: [
53+
"version": currentVersion,
54+
"build": currentBuild
5455
])
5556
}
56-
57-
let sourceApp: String? = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? ""
58-
let url: String? = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? ""
57+
58+
let sourceApp: String = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? ""
59+
let url: String = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? ""
5960

6061
analytics?.track(name: "Application Opened", properties: [
6162
"from_background": false,
62-
"version": currentVersion ?? "",
63-
"build": currentBuild ?? "",
64-
"referring_application": sourceApp ?? "",
65-
"url": url ?? ""
63+
"version": currentVersion,
64+
"build": currentBuild,
65+
"referring_application": sourceApp,
66+
"url": url
6667
])
6768

6869
UserDefaults.standard.setValue(currentVersion, forKey: Self.versionKey)

0 commit comments

Comments
 (0)