From 43db13444efa38d380b5521eb585c9ccc7fead27 Mon Sep 17 00:00:00 2001 From: Wipoo Shinsirikul <749739+mylifeasdog@users.noreply.github.com> Date: Fri, 19 Jan 2024 23:39:05 +0700 Subject: [PATCH] Fix Issue with Bundle path checking (closes #858) PR #859 --- .../UIKitScreenViewTracking.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/Core/ScreenViewTracking/UIKitScreenViewTracking.swift b/Sources/Core/ScreenViewTracking/UIKitScreenViewTracking.swift index 389cec01f..527186154 100644 --- a/Sources/Core/ScreenViewTracking/UIKitScreenViewTracking.swift +++ b/Sources/Core/ScreenViewTracking/UIKitScreenViewTracking.swift @@ -69,9 +69,15 @@ extension UIViewController { @objc func sp_viewDidAppear(_ animated: Bool) { sp_viewDidAppear(animated) - let bundle = Bundle(for: self.classForCoder) - if !bundle.bundlePath.hasPrefix(Bundle.main.bundlePath) { - // Ignore view controllers that don't start with the main bundle path + let bundleURL = Bundle(for: self.classForCoder).bundleURL + let mainBundleURL = Bundle.main.bundleURL + + // Resolve any symbolic links and standardize the file paths + let resolvedBundlePath = bundleURL.resolvingSymlinksInPath().path + let resolvedMainBundlePath = mainBundleURL.resolvingSymlinksInPath().path + + // Ignore view controllers that don't start with the main bundle path + guard resolvedBundlePath.hasPrefix(resolvedMainBundlePath) else { return } @@ -81,7 +87,7 @@ extension UIViewController { // Construct userInfo var userInfo: [AnyHashable : Any] = [:] userInfo["viewControllerClassName"] = String(describing: self.classForCoder) - userInfo["topViewControllerClassName"] = String(describing: top.self.classForCoder) + userInfo["topViewControllerClassName"] = String(describing: top.classForCoder) // `name` is set to snowplowId class instance variable if it exists (hence no @"id" in userInfo) userInfo["name"] = _SP_getName(self) ?? _SP_getName(top) ?? "Unknown"