Skip to content

Commit 96380e2

Browse files
authored
simplified app name determination (#397)
1 parent bcc4277 commit 96380e2

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

Sources/Segment/Plugins/Context.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,16 @@ public class Context: PlatformPlugin {
6161
"version": __segment_version,
6262
]
6363

64-
// app info
65-
let info = Bundle.main.infoDictionary
66-
let localizedInfo = Bundle.main.localizedInfoDictionary
67-
var app = [String: Any]()
68-
if let info = info {
69-
app.merge(info) { (_, new) in new }
70-
}
71-
if let localizedInfo = localizedInfo {
72-
app.merge(localizedInfo) { (_, new) in new }
73-
}
74-
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-
}
64+
// app information
65+
let info = Bundle.main.infoDictionary ?? [:]
66+
let localizedInfo = Bundle.main.localizedInfoDictionary ?? [:]
67+
let app = info.merging(localizedInfo) { _, localized in localized }
68+
69+
if !app.isEmpty {
70+
let name = app["CFBundleDisplayName"] as? String
71+
?? app["CFBundleName"] as? String
72+
?? ""
73+
8174
staticContext["app"] = [
8275
"name": name,
8376
"version": app["CFBundleShortVersionString"] ?? "",
@@ -87,7 +80,6 @@ public class Context: PlatformPlugin {
8780
}
8881

8982
insertStaticPlatformContextData(context: &staticContext)
90-
9183
return staticContext
9284
}
9385

0 commit comments

Comments
 (0)