Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recording: use non deprecated methods for getCurrentWindow if available #178

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading