Skip to content

Commit 8523efb

Browse files
authored
Add initial visionOS support (#271)
* Add initial visionOS support * Mention visionOS in README * Upate mark * Update another mark
1 parent 2fa2929 commit 8523efb

File tree

12 files changed

+25
-18
lines changed

12 files changed

+25
-18
lines changed

Examples/other_plugins/NotificationTracking.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ extension NotificationTracking: macOSLifecycle {
8080
#endif
8181
*/
8282

83-
// MARK: iOS/tvOS/Catalyst
83+
// MARK: iOS/tvOS/visionOS/Catalyst
8484

85-
#if os(tvOS) || os(iOS) || targetEnvironment(macCatalyst)
85+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
8686

8787
import UIKit
8888

Examples/tasks/NetBlockerFlushPolicy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension NetBlockerFlushPolicy: macOSLifecycle {
9797
}
9898
#endif
9999

100-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
100+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
101101
import UIKit
102102
extension NetBlockerFlushPolicy: iOSLifecycle {
103103
public func applicationDidBecomeActive(application: UIApplication?) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
![](https://github.com/segmentio/analytics-swift/actions/workflows/swift.yml/badge.svg)
33
![](https://img.shields.io/github/license/segmentio/analytics-swift)
44

5-
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.
5+
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/visionOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.
66

77
## How to get started
88
1. **Collect analytics data** from your app(s).

Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import Foundation
99

10-
// MARK: - iOS, tvOS, Catalyst
10+
// MARK: - iOS, tvOS, visionOS, Catalyst
1111

12-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
12+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
1313

1414
import SystemConfiguration
1515
import UIKit
@@ -30,6 +30,8 @@ internal class iOSVendorSystem: VendorSystem {
3030
return "ios"
3131
#elseif os(tvOS)
3232
return "tvos"
33+
#elseif os(visionOS)
34+
return "visionos"
3335
#elseif targetEnvironment(macCatalyst)
3436
return "macos"
3537
#else
@@ -60,8 +62,13 @@ internal class iOSVendorSystem: VendorSystem {
6062
}
6163

6264
override var screenSize: ScreenSize {
65+
#if os(iOS) || os(tvOS)
6366
let screenSize = UIScreen.main.bounds.size
6467
return ScreenSize(width: Double(screenSize.width), height: Double(screenSize.height))
68+
#elseif os(visionOS)
69+
let windowSize = UIApplication.shared.delegate?.window??.bounds.size
70+
return windowSize.map { ScreenSize(width: $0.width, height: $0.height) } ?? ScreenSize(width: 1280, height: 720)
71+
#endif
6572
}
6673

6774
override var userAgent: String? {
@@ -310,7 +317,7 @@ internal class MacOSVendorSystem: VendorSystem {
310317

311318
// MARK: - Reachability
312319

313-
#if os(iOS) || os(tvOS) || os(macOS) || targetEnvironment(macCatalyst)
320+
#if os(iOS) || os(tvOS) || os(visionOS) || os(macOS) || targetEnvironment(macCatalyst)
314321

315322
#if os(macOS)
316323
import SystemConfiguration

Sources/Segment/Plugins/Platforms/Vendors/VendorSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal class VendorSystem {
7070
}
7171

7272
static var current: VendorSystem = {
73-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
73+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
7474
return iOSVendorSystem()
7575
#elseif os(macOS)
7676
return MacOSVendorSystem()

Sources/Segment/Plugins/Platforms/iOS/iOSDelegation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
10+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
1111

1212
import UIKit
1313

Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleEvents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
10+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
1111

1212
import UIKit
1313

Sources/Segment/Plugins/Platforms/iOS/iOSLifecycleMonitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Cody Garvin on 12/4/20.
66
//
77

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

1010
import Foundation
1111
import UIKit

Sources/Segment/Startup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension Analytics: Subscriber {
4949

5050
// setup lifecycle if desired
5151
if configuration.values.trackApplicationLifecycleEvents, operatingMode != .synchronous {
52-
#if os(iOS) || os(tvOS)
52+
#if os(iOS) || os(tvOS) || os(visionOS) || os(visionOS)
5353
plugins.append(iOSLifecycleEvents())
5454
#endif
5555
#if os(watchOS)
@@ -72,7 +72,7 @@ extension Analytics: Subscriber {
7272
}
7373
}
7474

75-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
75+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
7676
import UIKit
7777
extension Analytics {
7878
internal func setupSettingsCheck() {

Tests/Segment-Tests/Analytics_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ final class Analytics_Tests: XCTestCase {
228228
XCTAssertTrue(token == "1234")
229229
}
230230

231-
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
231+
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
232232
func testDeviceTokenData() {
233233
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
234234
let outputReader = OutputReaderPlugin()

0 commit comments

Comments
 (0)