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
@@ -188,7 +188,7 @@ class PostHogContext {
188
188
// - "hw.model" returns mac model
189
189
#if targetEnvironment(macCatalyst)
190
190
sysctlName = " hw.model "
191
- #elseif os(iOS)
191
+ #elseif os(iOS) || os(visionOS)
192
192
if #available( iOS 14 . 0 , * ) {
193
193
if ProcessInfo . processInfo. isiOSAppOnMac {
194
194
sysctlName = " hw.model "
@@ -211,8 +211,14 @@ class PostHogContext {
211
211
properties [ " $screen_height " ] = Float ( screenSize. height)
212
212
}
213
213
214
- if Locale . current. languageCode != nil {
215
- properties [ " $locale " ] = Locale . current. languageCode
214
+ if #available( iOS 16 . 0 , * ) {
215
+ if let languageCode = Locale . current. language. languageCode {
216
+ properties [ " $locale " ] = languageCode. identifier
217
+ }
218
+ } else {
219
+ if Locale . current. languageCode != nil {
220
+ properties [ " $locale " ] = Locale . current. languageCode
221
+ }
216
222
}
217
223
properties [ " $timezone " ] = TimeZone . current. identifier
218
224
@@ -227,7 +233,7 @@ class PostHogContext {
227
233
}
228
234
229
235
private func registerNotifications( ) {
230
- #if os(iOS) || os(tvOS)
236
+ #if os(iOS) || os(tvOS) || os(visionOS)
231
237
#if os(iOS)
232
238
NotificationCenter . default. addObserver ( self ,
233
239
selector: #selector( onOrientationDidChange) ,
@@ -262,7 +268,7 @@ class PostHogContext {
262
268
}
263
269
264
270
private func unregisterNotifications( ) {
265
- #if os(iOS) || os(tvOS)
271
+ #if os(iOS) || os(tvOS) || os(visionOS)
266
272
#if os(iOS)
267
273
NotificationCenter . default. removeObserver ( self ,
268
274
name: UIDevice . orientationDidChangeNotification,
@@ -293,7 +299,7 @@ class PostHogContext {
293
299
294
300
/// Retrieves the current screen size of the application window based on platform
295
301
private func getScreenSize( ) -> CGSize ? {
296
- #if os(iOS) || os(tvOS)
302
+ #if os(iOS) || os(tvOS) || os(visionOS)
297
303
return UIApplication . getCurrentWindow ( filterForegrounded: false ) ? . bounds. size
298
304
#elseif os(macOS)
299
305
// NSScreen.frame represents the full screen rectangle and includes any space occupied by menu, dock or camera bezel
0 commit comments