Skip to content

Commit

Permalink
Fix SwiftUI screen size handling on iOS (#238)
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 #237
  • Loading branch information
terabyte128 authored Nov 8, 2024
1 parent 7f5810e commit 22d9eb1
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 22d9eb1

Please sign in to comment.