From 22d9eb1bc35c0523c0524eca6d1a505e360ad2e2 Mon Sep 17 00:00:00 2001 From: Sam Wolfson Date: Thu, 7 Nov 2024 23:41:13 -0800 Subject: [PATCH] Fix SwiftUI screen size handling on iOS (#238) UIScreen.main is deprecated and calling it appears to reset the accent color of the UI. Fixes #237 --- PostHog/PostHogContext.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PostHog/PostHogContext.swift b/PostHog/PostHogContext.swift index 2042c58e8..54fd1d4b7 100644 --- a/PostHog/PostHogContext.swift +++ b/PostHog/PostHogContext.swift @@ -123,8 +123,10 @@ class PostHogContext { var properties: [String: Any] = [:] #if os(iOS) || os(tvOS) - properties["$screen_width"] = Float(UIScreen.main.bounds.width) - properties["$screen_height"] = Float(UIScreen.main.bounds.height) + if let screen = UIApplication.shared.windows.first?.screen { + properties["$screen_width"] = Float(screen.bounds.width) + properties["$screen_height"] = Float(screen.bounds.height) + } #elseif os(macOS) if let mainScreen = NSScreen.main { let screenFrame = mainScreen.visibleFrame