Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Examples/other_plugins/NotificationTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ extension NotificationTracking: macOSLifecycle {
#endif
*/

// MARK: iOS/tvOS/Catalyst
// MARK: iOS/tvOS/visionOS/Catalyst

#if os(tvOS) || os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)

import UIKit

Expand Down
2 changes: 1 addition & 1 deletion Examples/tasks/NetBlockerFlushPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension NetBlockerFlushPolicy: macOSLifecycle {
}
#endif

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
import UIKit
extension NetBlockerFlushPolicy: iOSLifecycle {
public func applicationDidBecomeActive(application: UIApplication?) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
![](https://github.com/segmentio/analytics-swift/actions/workflows/swift.yml/badge.svg)
![](https://img.shields.io/github/license/segmentio/analytics-swift)

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.
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.

## How to get started
1. **Collect analytics data** from your app(s).
Expand Down
13 changes: 10 additions & 3 deletions Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation

// MARK: - iOS, tvOS, Catalyst
// MARK: - iOS, tvOS, visionOS, Catalyst

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)

import SystemConfiguration
import UIKit
Expand All @@ -30,6 +30,8 @@ internal class iOSVendorSystem: VendorSystem {
return "ios"
#elseif os(tvOS)
return "tvos"
#elseif os(visionOS)
return "visionos"
#elseif targetEnvironment(macCatalyst)
return "macos"
#else
Expand Down Expand Up @@ -60,8 +62,13 @@ internal class iOSVendorSystem: VendorSystem {
}

override var screenSize: ScreenSize {
#if os(iOS) || os(tvOS)
let screenSize = UIScreen.main.bounds.size
return ScreenSize(width: Double(screenSize.width), height: Double(screenSize.height))
#elseif os(visionOS)
let windowSize = UIApplication.shared.delegate?.window??.bounds.size
return windowSize.map { ScreenSize(width: $0.width, height: $0.height) } ?? ScreenSize(width: 1280, height: 720)
#endif
}

override var userAgent: String? {
Expand Down Expand Up @@ -310,7 +317,7 @@ internal class MacOSVendorSystem: VendorSystem {

// MARK: - Reachability

#if os(iOS) || os(tvOS) || os(macOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || os(macOS) || targetEnvironment(macCatalyst)

#if os(macOS)
import SystemConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class VendorSystem {
}

static var current: VendorSystem = {
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
return iOSVendorSystem()
#elseif os(macOS)
return MacOSVendorSystem()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Segment/Plugins/Platforms/iOS/iOSDelegation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)

import UIKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)

import UIKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Cody Garvin on 12/4/20.
//

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)

import Foundation
import UIKit
Expand Down
4 changes: 2 additions & 2 deletions Sources/Segment/Startup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension Analytics: Subscriber {

// setup lifecycle if desired
if configuration.values.trackApplicationLifecycleEvents, operatingMode != .synchronous {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS) || os(visionOS)
plugins.append(iOSLifecycleEvents())
#endif
#if os(watchOS)
Expand All @@ -72,7 +72,7 @@ extension Analytics: Subscriber {
}
}

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
import UIKit
extension Analytics {
internal func setupSettingsCheck() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Segment-Tests/Analytics_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ final class Analytics_Tests: XCTestCase {
XCTAssertTrue(token == "1234")
}

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
func testDeviceTokenData() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
Expand Down
6 changes: 3 additions & 3 deletions Tests/Segment-Tests/MemoryLeak_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class MemoryLeak_Tests: XCTestCase {
#if !os(Linux)
let deviceToken = analytics.find(pluginType: DeviceToken.self)!
#endif
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
let iosLifecycle = analytics.find(pluginType: iOSLifecycleEvents.self)!
let iosMonitor = analytics.find(pluginType: iOSLifecycleMonitor.self)!
#elseif os(watchOS)
Expand All @@ -59,7 +59,7 @@ final class MemoryLeak_Tests: XCTestCase {
#if !os(Linux)
analytics.remove(plugin: deviceToken)
#endif
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
analytics.remove(plugin: iosLifecycle)
analytics.remove(plugin: iosMonitor)
#elseif os(watchOS)
Expand All @@ -80,7 +80,7 @@ final class MemoryLeak_Tests: XCTestCase {
#if !os(Linux)
checkIfLeaked(deviceToken)
#endif
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
checkIfLeaked(iosLifecycle)
checkIfLeaked(iosMonitor)
#elseif os(watchOS)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Segment-Tests/iOSLifecycle_Tests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import Segment

#if os(iOS)
#if os(iOS) || os(tvOS) || os(visionOS)
final class iOSLifecycle_Tests: XCTestCase {

func testInstallEventCreation() {
Expand Down