Skip to content

Commit 7498b61

Browse files
fix: extract NSURL from launch options (#394)
1 parent ddbbec2 commit 7498b61

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle {
5656
}
5757

5858
let sourceApp: String = launchOptions?[UIApplication.LaunchOptionsKey.sourceApplication] as? String ?? ""
59-
let url: String = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String ?? ""
59+
let url = urlFrom(launchOptions)
6060

6161
analytics?.track(name: "Application Opened", properties: [
6262
"from_background": false,
@@ -101,6 +101,16 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle {
101101
}
102102
analytics?.track(name: "Application Foregrounded")
103103
}
104+
105+
private func urlFrom(_ launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> String {
106+
if let url = launchOptions?[UIApplication.LaunchOptionsKey.url] as? String {
107+
return url
108+
}
109+
if let url = launchOptions?[UIApplication.LaunchOptionsKey.url] as? NSURL, let rawUrl = url.absoluteString {
110+
return rawUrl
111+
}
112+
return ""
113+
}
104114
}
105115

106116
#endif

0 commit comments

Comments
 (0)