Skip to content

Commit

Permalink
Fix SwiftUI screen size handling on iOS
Browse files Browse the repository at this point in the history
UIScreen.main is deprecated and calling it appears to reset
the accent color of the UI.

Fixes #54
  • Loading branch information
terabyte128 committed Nov 8, 2024
1 parent 7f5810e commit 882ed55
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions PostHog/PostHogContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 882ed55

Please sign in to comment.