7
7
8
8
import Foundation
9
9
10
- #if os(iOS) || os(tvOS)
10
+ #if os(iOS) || os(tvOS) || os(visionOS)
11
11
import UIKit
12
12
#elseif os(macOS)
13
13
import AppKit
@@ -55,7 +55,7 @@ class PostHogContext {
55
55
56
56
// iOS app running in compatibility mode (Designed for iPad/iPhone)
57
57
var isiOSAppOnMac = false
58
- #if os(iOS)
58
+ #if os(iOS) || os(visionOS)
59
59
if #available( iOS 14 . 0 , * ) {
60
60
isiOSAppOnMac = ProcessInfo . processInfo. isiOSAppOnMac
61
61
}
@@ -71,7 +71,7 @@ class PostHogContext {
71
71
properties [ " $is_ios_running_on_mac " ] = isiOSAppOnMac
72
72
properties [ " $is_mac_catalyst_app " ] = isMacCatalystApp
73
73
74
- #if os(iOS) || os(tvOS)
74
+ #if os(iOS) || os(tvOS) || os(visionOS)
75
75
let device = UIDevice . current
76
76
// use https://github.com/devicekit/DeviceKit
77
77
let processInfo = ProcessInfo . processInfo
@@ -118,6 +118,8 @@ class PostHogContext {
118
118
deviceType = " CarPlay "
119
119
case UIUserInterfaceIdiom . mac:
120
120
deviceType = " Desktop "
121
+ case UIUserInterfaceIdiom . vision:
122
+ deviceType = " Vision "
121
123
default :
122
124
deviceType = nil
123
125
}
@@ -188,7 +190,7 @@ class PostHogContext {
188
190
// - "hw.model" returns mac model
189
191
#if targetEnvironment(macCatalyst)
190
192
sysctlName = " hw.model "
191
- #elseif os(iOS)
193
+ #elseif os(iOS) || os(visionOS)
192
194
if #available( iOS 14 . 0 , * ) {
193
195
if ProcessInfo . processInfo. isiOSAppOnMac {
194
196
sysctlName = " hw.model "
@@ -211,8 +213,14 @@ class PostHogContext {
211
213
properties [ " $screen_height " ] = Float ( screenSize. height)
212
214
}
213
215
214
- if Locale . current. languageCode != nil {
215
- properties [ " $locale " ] = Locale . current. languageCode
216
+ if #available( iOS 16 . 0 , macOS 13 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * ) {
217
+ if let languageCode = Locale . current. language. languageCode {
218
+ properties [ " $locale " ] = languageCode. identifier
219
+ }
220
+ } else {
221
+ if Locale . current. languageCode != nil {
222
+ properties [ " $locale " ] = Locale . current. languageCode
223
+ }
216
224
}
217
225
properties [ " $timezone " ] = TimeZone . current. identifier
218
226
@@ -227,7 +235,7 @@ class PostHogContext {
227
235
}
228
236
229
237
private func registerNotifications( ) {
230
- #if os(iOS) || os(tvOS)
238
+ #if os(iOS) || os(tvOS) || os(visionOS)
231
239
#if os(iOS)
232
240
NotificationCenter . default. addObserver ( self ,
233
241
selector: #selector( onOrientationDidChange) ,
@@ -262,7 +270,7 @@ class PostHogContext {
262
270
}
263
271
264
272
private func unregisterNotifications( ) {
265
- #if os(iOS) || os(tvOS)
273
+ #if os(iOS) || os(tvOS) || os(visionOS)
266
274
#if os(iOS)
267
275
NotificationCenter . default. removeObserver ( self ,
268
276
name: UIDevice . orientationDidChangeNotification,
@@ -293,7 +301,7 @@ class PostHogContext {
293
301
294
302
/// Retrieves the current screen size of the application window based on platform
295
303
private func getScreenSize( ) -> CGSize ? {
296
- #if os(iOS) || os(tvOS)
304
+ #if os(iOS) || os(tvOS) || os(visionOS)
297
305
return UIApplication . getCurrentWindow ( filterForegrounded: false ) ? . bounds. size
298
306
#elseif os(macOS)
299
307
// NSScreen.frame represents the full screen rectangle and includes any space occupied by menu, dock or camera bezel
0 commit comments