Skip to content

Commit 6718e8a

Browse files
committed
Add support for visionOS
1 parent 5077fa8 commit 6718e8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+158
-101
lines changed

PostHog.xcodeproj/project.pbxproj

+79-37
Large diffs are not rendered by default.

PostHog/App Life Cycle/ApplicationLifecyclePublisher.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Yiannis Josephides on 16/12/2024.
66
//
77

8-
#if os(iOS) || os(tvOS)
8+
#if os(iOS) || os(tvOS) || os(visionOS)
99
import UIKit
1010
#elseif os(macOS)
1111
import AppKit
@@ -49,7 +49,7 @@ final class ApplicationLifecyclePublisher: BaseApplicationLifecyclePublisher {
4949

5050
let defaultCenter = NotificationCenter.default
5151

52-
#if os(iOS) || os(tvOS)
52+
#if os(iOS) || os(tvOS) || os(visionOS)
5353
defaultCenter.addObserver(self,
5454
selector: #selector(appDidFinishLaunching),
5555
name: UIApplication.didFinishLaunchingNotification,

PostHog/DI.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum DI {
1717
// publishes global screen view events (UIViewController.viewDidAppear)
1818
lazy var screenViewPublisher: ScreenViewPublishing = ApplicationScreenViewPublisher.shared
1919

20-
#if os(iOS) || os(tvOS)
20+
#if os(iOS) || os(tvOS) || os(visionOS)
2121
// publishes global application events (UIApplication.sendEvent)
2222
lazy var applicationEventPublisher: ApplicationEventPublishing = ApplicationEventPublisher.shared
2323
#endif

PostHog/PostHogConfig.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import Foundation
6363
/// or EU Host: 'https://eu.i.posthog.com'
6464
public static let defaultHost: String = "https://us.i.posthog.com"
6565

66-
#if os(iOS)
66+
#if os(iOS) || os(visionOS)
6767
/// Enable Recording of Session Replays for iOS
6868
/// Default: false
6969
@objc public var sessionReplay: Bool = false
@@ -106,7 +106,7 @@ import Foundation
106106
integrations.append(PostHogAppLifeCycleIntegration())
107107
}
108108

109-
#if os(iOS)
109+
#if os(iOS) || os(visionOS)
110110
if sessionReplay {
111111
integrations.append(PostHogReplayIntegration())
112112
}

PostHog/PostHogContext.swift

+15-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
#if os(iOS) || os(tvOS)
10+
#if os(iOS) || os(tvOS) || os(visionOS)
1111
import UIKit
1212
#elseif os(macOS)
1313
import AppKit
@@ -55,7 +55,7 @@ class PostHogContext {
5555

5656
// iOS app running in compatibility mode (Designed for iPad/iPhone)
5757
var isiOSAppOnMac = false
58-
#if os(iOS)
58+
#if os(iOS) || os(visionOS)
5959
if #available(iOS 14.0, *) {
6060
isiOSAppOnMac = ProcessInfo.processInfo.isiOSAppOnMac
6161
}
@@ -71,7 +71,7 @@ class PostHogContext {
7171
properties["$is_ios_running_on_mac"] = isiOSAppOnMac
7272
properties["$is_mac_catalyst_app"] = isMacCatalystApp
7373

74-
#if os(iOS) || os(tvOS)
74+
#if os(iOS) || os(tvOS) || os(visionOS)
7575
let device = UIDevice.current
7676
// use https://github.com/devicekit/DeviceKit
7777
let processInfo = ProcessInfo.processInfo
@@ -188,7 +188,7 @@ class PostHogContext {
188188
// - "hw.model" returns mac model
189189
#if targetEnvironment(macCatalyst)
190190
sysctlName = "hw.model"
191-
#elseif os(iOS)
191+
#elseif os(iOS) || os(visionOS)
192192
if #available(iOS 14.0, *) {
193193
if ProcessInfo.processInfo.isiOSAppOnMac {
194194
sysctlName = "hw.model"
@@ -211,8 +211,14 @@ class PostHogContext {
211211
properties["$screen_height"] = Float(screenSize.height)
212212
}
213213

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+
}
216222
}
217223
properties["$timezone"] = TimeZone.current.identifier
218224

@@ -227,7 +233,7 @@ class PostHogContext {
227233
}
228234

229235
private func registerNotifications() {
230-
#if os(iOS) || os(tvOS)
236+
#if os(iOS) || os(tvOS) || os(visionOS)
231237
#if os(iOS)
232238
NotificationCenter.default.addObserver(self,
233239
selector: #selector(onOrientationDidChange),
@@ -262,7 +268,7 @@ class PostHogContext {
262268
}
263269

264270
private func unregisterNotifications() {
265-
#if os(iOS) || os(tvOS)
271+
#if os(iOS) || os(tvOS) || os(visionOS)
266272
#if os(iOS)
267273
NotificationCenter.default.removeObserver(self,
268274
name: UIDevice.orientationDidChangeNotification,
@@ -293,7 +299,7 @@ class PostHogContext {
293299

294300
/// Retrieves the current screen size of the application window based on platform
295301
private func getScreenSize() -> CGSize? {
296-
#if os(iOS) || os(tvOS)
302+
#if os(iOS) || os(tvOS) || os(visionOS)
297303
return UIApplication.getCurrentWindow(filterForegrounded: false)?.bounds.size
298304
#elseif os(macOS)
299305
// NSScreen.frame represents the full screen rectangle and includes any space occupied by menu, dock or camera bezel

PostHog/PostHogFeatureFlags.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class PostHogFeatureFlags {
135135
}
136136
let errorsWhileComputingFlags = data?["errorsWhileComputingFlags"] as? Bool ?? false
137137

138-
#if os(iOS)
138+
#if os(iOS) || os(visionOS)
139139
if let sessionRecording = data?["sessionRecording"] as? Bool {
140140
self.sessionReplayFlagActive = sessionRecording
141141

@@ -276,7 +276,7 @@ class PostHogFeatureFlags {
276276
return value
277277
}
278278

279-
#if os(iOS)
279+
#if os(iOS) || os(visionOS)
280280
func isSessionReplayFlagActive() -> Bool {
281281
sessionReplayFlagActive
282282
}

PostHog/PostHogSDK.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import Foundation
1111

12-
#if os(iOS) || os(tvOS)
12+
#if os(iOS) || os(tvOS) || os(visionOS)
1313
import UIKit
1414
#elseif os(macOS)
1515
import AppKit
@@ -308,7 +308,7 @@ let maxRetryDelay = 30.0
308308
}
309309
// only Session replay requires $window_id, so we set as the same as $session_id.
310310
// the backend might fallback to $session_id if $window_id is not present next.
311-
#if os(iOS)
311+
#if os(iOS) || os(visionOS)
312312
if !appendSharedProps, isSessionReplayActive() {
313313
props["$window_id"] = sessionId
314314
}
@@ -967,7 +967,7 @@ let maxRetryDelay = 30.0
967967
}
968968
}
969969

970-
#if os(iOS)
970+
#if os(iOS) || os(visionOS)
971971
/**
972972
Starts session recording.
973973
This method will have no effect if PostHog is not enabled, or if session replay is disabled in your project settings
@@ -1051,7 +1051,7 @@ let maxRetryDelay = 30.0
10511051
return postHog
10521052
}
10531053

1054-
#if os(iOS)
1054+
#if os(iOS) || os(visionOS)
10551055
@objc public func isSessionReplayActive() -> Bool {
10561056
if !isEnabled() {
10571057
return false
@@ -1113,7 +1113,7 @@ let maxRetryDelay = 30.0
11131113
}
11141114
#endif
11151115

1116-
#if os(iOS)
1116+
#if os(iOS) || os(visionOS)
11171117
func getReplayIntegration() -> PostHogReplayIntegration? {
11181118
installedIntegrations.compactMap {
11191119
$0 as? PostHogReplayIntegration

PostHog/PostHogSessionManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ import Foundation
224224
private var applicationEventToken: RegistrationToken?
225225

226226
private func registerApplicationSendEvent() {
227-
#if os(iOS) || os(tvOS)
227+
#if os(iOS) || os(tvOS) || os(visionOS)
228228
let applicationEventPublisher = DI.main.applicationEventPublisher
229229
applicationEventToken = applicationEventPublisher.onApplicationEvent { [weak self] _, _ in
230230
// update "last active" session

PostHog/Replay/ApplicationEventPublisher.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
#if os(iOS) || os(tvOS)
10+
#if os(iOS) || os(tvOS) || os(visionOS)
1111
import UIKit
1212

1313
typealias ApplicationEventHandler = (_ event: UIEvent, _ date: Date) -> Void

PostHog/Replay/CGColor+Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Manoel Aranda Neto on 21.03.24.
66
//
77

8-
#if os(iOS)
8+
#if os(iOS) || os(visionOS)
99

1010
import Foundation
1111
import UIKit

PostHog/Replay/CGSize+Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Manoel Aranda Neto on 24.07.24.
66
//
77

8-
#if os(iOS)
8+
#if os(iOS) || os(visionOS)
99
import Foundation
1010

1111
extension CGSize {

PostHog/Replay/MethodSwizzler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright 2019-Present Datadog, Inc.
55
*/
66

7-
#if os(iOS)
7+
#if os(iOS) || os(visionOS)
88
import Foundation
99

1010
class MethodSwizzler<TypedIMP, TypedBlockIMP> {

PostHog/Replay/NetworkSample.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Manoel Aranda Neto on 26.03.24.
66
//
77

8-
#if os(iOS)
8+
#if os(iOS) || os(visionOS)
99
import Foundation
1010

1111
struct NetworkSample {

PostHog/Replay/PostHogReplayIntegration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Created by Manoel Aranda Neto on 19.03.24.
88
//
9-
#if os(iOS)
9+
#if os(iOS) || os(visionOS)
1010
import Foundation
1111
import PhotosUI
1212
import SwiftUI

PostHog/Replay/PostHogSessionReplayConfig.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by Manoel Aranda Neto on 19.03.24.
66
//
7-
#if os(iOS)
7+
#if os(iOS) || os(visionOS)
88
import Foundation
99

1010
@objc(PostHogSessionReplayConfig) public class PostHogSessionReplayConfig: NSObject {

PostHog/Replay/RRWireframe.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99

1010
import Foundation
11-
#if os(iOS)
11+
#if os(iOS) || os(visionOS)
1212
import UIKit
1313
#endif
1414

@@ -24,7 +24,7 @@ class RRWireframe {
2424
var text: String?
2525
var label: String?
2626
var value: Any? // string or number
27-
#if os(iOS)
27+
#if os(iOS) || os(visionOS)
2828
var image: UIImage?
2929
var maskableWidgets: [CGRect]?
3030
#endif
@@ -37,7 +37,7 @@ class RRWireframe {
3737
// internal
3838
var parentId: Int?
3939

40-
#if os(iOS)
40+
#if os(iOS) || os(visionOS)
4141
private func maskImage() -> UIImage? {
4242
if let image = image {
4343
// the scale also affects the image size/resolution, from usually 100kb to 15kb each
@@ -92,7 +92,7 @@ class RRWireframe {
9292
dict["value"] = value
9393
}
9494

95-
#if os(iOS)
95+
#if os(iOS) || os(visionOS)
9696
if let image = image {
9797
if let maskedImage = maskImage() {
9898
base64 = maskedImage.toBase64()

PostHog/Replay/UIColor+Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by Manoel Aranda Neto on 21.03.24.
66
//
7-
#if os(iOS)
7+
#if os(iOS) || os(visionOS)
88

99
import Foundation
1010
import UIKit

PostHog/Replay/UIImage+Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Manoel Aranda Neto on 27.11.24.
66
//
77

8-
#if os(iOS)
8+
#if os(iOS) || os(visionOS)
99
import Foundation
1010
import UIKit
1111

PostHog/Replay/UITextInputTraits+Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Manoel Aranda Neto on 21.03.24.
66
//
77

8-
#if os(iOS)
8+
#if os(iOS) || os(visionOS)
99
import Foundation
1010
import UIKit
1111

PostHog/Replay/UIView+Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Manoel Aranda Neto on 21.03.24.
66
//
77

8-
#if os(iOS)
8+
#if os(iOS) || os(visionOS)
99
import Foundation
1010
import UIKit
1111

PostHog/Replay/URLSessionExtension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS)
1+
#if os(iOS) || os(visionOS)
22
import Foundation
33

44
public extension URLSession {

PostHog/Replay/URLSessionInterceptor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright 2019-Present Datadog, Inc.
55
*/
66

7-
#if os(iOS)
7+
#if os(iOS) || os(visionOS)
88

99
import Foundation
1010

PostHog/Replay/URLSessionSwizzler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright 2019-Present Datadog, Inc.
77
*/
88

9-
#if os(iOS)
9+
#if os(iOS) || os(visionOS)
1010

1111
import Foundation
1212

PostHog/Replay/ViewLayoutTracker.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS)
1+
#if os(iOS) || os(visionOS)
22
import Foundation
33
import UIKit
44

0 commit comments

Comments
 (0)