Skip to content

Commit

Permalink
Fix Issue with Bundle path checking (closes snowplow#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
mylifeasdog committed Jan 18, 2024
1 parent cc13625 commit 1b287e3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Sources/Core/ScreenViewTracking/UIKitScreenViewTracking.swift
Expand Up @@ -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
}

Expand All @@ -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"
Expand Down

0 comments on commit 1b287e3

Please sign in to comment.