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

PostHog causes accent color in SwiftUI app to be reset #237

Closed
terabyte128 opened this issue Nov 8, 2024 · 0 comments
Closed

PostHog causes accent color in SwiftUI app to be reset #237

terabyte128 opened this issue Nov 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@terabyte128
Copy link
Contributor

Version

3.14.1

Steps to Reproduce

  1. Initialize PostHog in a SwiftUI iOS app, like this:
let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST)
config.captureScreenViews = false
config.sessionReplay = true
config.sessionReplayConfig.screenshotMode = true
config.sessionReplayConfig.maskAllTextInputs = false
config.sessionReplayConfig.maskAllImages = false
PostHogSDK.shared.setup(config)
  1. Run the app

Expected Result

The accent color defined in the app's assets is respected.

Actual Result

It is not.

I believe this is a regression of of #54. It seems that when the library was re-written in Swift, it began using the deprecated UIScreen.main symbol again. Applying the following diff appears to fix it:

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
@terabyte128 terabyte128 added the bug Something isn't working label Nov 8, 2024
terabyte128 added a commit to terabyte128/posthog-ios that referenced this issue Nov 8, 2024
UIScreen.main is deprecated and calling it appears to reset
the accent color of the UI.

Fixes PostHog#237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant