Skip to content

Commit

Permalink
recording: use non deprecated methods for getCurrentWindow if availab…
Browse files Browse the repository at this point in the history
…le (#178)
  • Loading branch information
marandaneto authored Sep 3, 2024
1 parent 4babdc5 commit 967a3df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- recording: use non deprecated methods for getCurrentWindow if available ([#178](https://github.com/PostHog/posthog-ios/pull/178))

## 3.8.2 - 2024-09-03

- chore: cache flags, distinct id and anon id in memory to avoid file IO every time ([#177](https://github.com/PostHog/posthog-ios/pull/177))
Expand Down
25 changes: 19 additions & 6 deletions PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,27 @@
}

static func getCurrentWindow() -> UIWindow? {
guard let activeScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) else {
return nil
}
// TODO: support multi windows

// UIApplication.shared.windows is deprecated
for scene in UIApplication.shared.connectedScenes {
if scene is UIWindowScene,
scene.activationState == .foregroundActive,
let windowScene = scene as? UIWindowScene
{
if #available(iOS 15.0, *) {
if let keyWindow = windowScene.keyWindow {
return keyWindow
}
}

guard let window = (activeScene as? UIWindowScene)?.windows.first(where: { $0.isKeyWindow }) else {
return nil
for window in windowScene.windows where window.isKeyWindow {
return window
}
}
}
return window

return nil
}

@objc private func snapshot() {
Expand Down

0 comments on commit 967a3df

Please sign in to comment.