diff --git a/CHANGELOG.md b/CHANGELOG.md index b92dfbb7c..021e1f269 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- fix: ignore additional keyboard windows for $screen event ([#279](https://github.com/PostHog/posthog-ios/pull/279)) + ## 3.17.1 - 2024-12-18 - fix: avoid masking SwiftUI Gradient views ([#275](https://github.com/PostHog/posthog-ios/pull/275)) diff --git a/PostHog/UIViewController.swift b/PostHog/UIViewController.swift index 38327a00a..6fa15a32d 100644 --- a/PostHog/UIViewController.swift +++ b/PostHog/UIViewController.swift @@ -60,7 +60,6 @@ @objc func viewDidAppearOverride(animated: Bool) { // ignore views from keyboard window - // these may include: UIInputWindowController, _UICursorAccessoryViewController, UICompatibilityInputViewController,UIKeyboardHiddenViewController_Autofill and others if let window = viewIfLoaded?.window, !window.isKeyboardWindow { captureScreenView(window) } diff --git a/PostHog/Utils/UIWindow+.swift b/PostHog/Utils/UIWindow+.swift index d6d2075cd..f11970803 100644 --- a/PostHog/Utils/UIWindow+.swift +++ b/PostHog/Utils/UIWindow+.swift @@ -9,9 +9,42 @@ import Foundation import UIKit + /** + Known keyboard window (private) types + + ## UIRemoteKeyboardWindow + This is the window that manages the actual keyboard + + The following system view controllers were observed to be presented in a UIRemoteKeyboardWindow window + - UIInputWindowController + - UICompatibilityInputViewController + - UISystemInputAssistantViewController + - UIPredictionViewController + - UISystemKeyboardDockController + - TUIEmojiSearchInputViewController + - STKPrewarmingViewController + - STKStickerRemoteSearchViewController + - _UIRemoteInputViewController + - _UISceneHostingViewController + - STKEmojiAndStickerCollectionViewController + + ## UITextEffectsWindow + Hosts system components like the magnifying glass for text selection, predictive text suggestions, copy/paste menus, input accessory views etc. + + The following system view controllers were observed to be presented in a UITextEffectsWindow window + - UIInputWindowController + - UICompatibilityInputViewController + + These view controllers should not appear in a $screen event. If they do, then it means that they are presented in a UIWindow not listed below + */ + private let knownKeyboardWindowTypes: [String] = [ + "UIRemoteKeyboardWindow", + "UITextEffectsWindow", + ] + extension UIWindow { var isKeyboardWindow: Bool { - String(describing: type(of: window)) == "UIRemoteKeyboardWindow" + knownKeyboardWindowTypes.contains(String(describing: type(of: self))) } } #endif