Skip to content

Commit

Permalink
Add support for visionOS (#830)
Browse files Browse the repository at this point in the history
Co-authored-by: Miranda Wilson <[email protected]>
  • Loading branch information
matus-tomlein and mscwilson authored Jan 16, 2024
1 parent f08393c commit 4831e4d
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 55 deletions.
41 changes: 35 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push]
jobs:
podspec:
name: Lint Podspec for ${{ matrix.platform }}
runs-on: macos-latest
runs-on: macos-13
strategy:
matrix:
platform: [ios, ios, osx, tvos, watchos]
Expand Down Expand Up @@ -53,6 +53,7 @@ jobs:
xcode-version: 13.4
destination: "platform=tvOS Simulator,name=Apple TV"
target: Tests

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -110,8 +111,22 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: 15.5, iphone: iPhone 12 Pro, watchos: 8.5, watch: Apple Watch Series 5 - 44mm, macos: '12', xcode: 13.4}
- {ios: 14.4, iphone: iPhone 8, watchos: 7.2, watch: Apple Watch Series 4 - 40mm, macos: '11', xcode: 12.4}
- {
ios: 15.5,
iphone: iPhone 12 Pro,
watchos: 8.5,
watch: Apple Watch Series 5 - 44mm,
macos: "12",
xcode: 13.4,
}
- {
ios: 14.4,
iphone: iPhone 8,
watchos: 7.2,
watch: Apple Watch Series 4 - 40mm,
macos: "11",
xcode: 12.4,
}

steps:
- name: Checkout
Expand Down Expand Up @@ -141,7 +156,14 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: '14.4', iphone: iPhone 12 Pro, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '11', xcode: 12.4}
- {
ios: "14.4",
iphone: iPhone 12 Pro,
watchos: "7.2",
watch: Apple Watch Series 5 - 44mm,
macos: "11",
xcode: 12.4,
}

steps:
- name: Checkout
Expand Down Expand Up @@ -171,7 +193,14 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: '14.4', iphone: iPhone 11 Pro, watchos: '7.2', watch: Apple Watch Series 5 - 44mm, macos: '11', xcode: 12.4}
- {
ios: "14.4",
iphone: iPhone 11 Pro,
watchos: "7.2",
watch: Apple Watch Series 5 - 44mm,
macos: "11",
xcode: 12.4,
}

steps:
- name: Checkout
Expand Down Expand Up @@ -217,7 +246,7 @@ jobs:
fail-fast: false
matrix:
version:
- {ios: 15.5, iphone: iPhone 12 Pro, macos: '12', xcode: 13.4}
- { ios: 15.5, iphone: iPhone 12 Pro, macos: "12", xcode: 13.4 }

steps:
- name: Checkout
Expand Down
42 changes: 20 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"object": {
"pins": [
{
"package": "Mocker",
"repositoryURL": "https://github.com/WeTransfer/Mocker.git",
"state": {
"branch": null,
"revision": "5d86f27a8f80d4ba388bc1a379a3c2289a1f3d18",
"version": "2.6.0"
}
},
{
"package": "SwiftDocCPlugin",
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
"state": {
"branch": null,
"revision": "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"version": "1.0.0"
}
"pins" : [
{
"identity" : "mocker",
"kind" : "remoteSourceControl",
"location" : "https://github.com/WeTransfer/Mocker.git",
"state" : {
"revision" : "5d86f27a8f80d4ba388bc1a379a3c2289a1f3d18",
"version" : "2.6.0"
}
]
},
"version": 1
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"version" : "1.0.0"
}
}
],
"version" : 2
}
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// swift-tools-version:5.2
// swift-tools-version:5.3.0

import PackageDescription

let package = Package(
name: "SnowplowTracker",
defaultLocalization: "en",
platforms: [
.macOS("10.13"),
.iOS("11.0"),
Expand Down
46 changes: 46 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "SnowplowTracker",
defaultLocalization: "en",
platforms: [
.macOS("10.13"),
.iOS("11.0"),
.tvOS("12.0"),
.watchOS("6.0"),
.visionOS("1.0")
],
products: [
.library(
name: "SnowplowTracker",
targets: ["SnowplowTracker"]),
],
dependencies: [
.package(name: "Mocker", url: "https://github.com/WeTransfer/Mocker.git", from: "2.5.4"),
],
targets: [
.target(
name: "SnowplowTracker",
path: "./Sources"),
.testTarget(
name: "Tests",
dependencies: [
"SnowplowTracker",
"Mocker"
],
path: "Tests"),
.testTarget(
name: "IntegrationTests",
dependencies: [
"SnowplowTracker"
],
path: "IntegrationTests")
]
)
#if swift(>=5.6)
package.dependencies += [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
]
#endif
5 changes: 5 additions & 0 deletions SnowplowTracker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Pod::Spec.new do |s|
s.ios.frameworks = 'CoreTelephony', 'UIKit', 'Foundation'
s.osx.frameworks = 'AppKit', 'Foundation'
s.tvos.frameworks = 'UIKit', 'Foundation'

if s.respond_to?(:visionos)
s.visionos.deployment_target = '1.0'
s.visionos.frameworks = 'UIKit', 'Foundation'
end

s.pod_target_xcconfig = { "DEFINES_MODULE" => "YES" }
end
2 changes: 1 addition & 1 deletion Sources/Core/Storage/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the Apache License Version 2.0 for the specific
// language governing permissions and limitations there under.

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS)

import Foundation
import SQLite3
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Storage/SQLiteEventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the Apache License Version 2.0 for the specific
// language governing permissions and limitations there under.

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS)

import Foundation

Expand Down
8 changes: 4 additions & 4 deletions Sources/Core/Subject/PlatformContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// language governing permissions and limitations there under.

import Foundation
#if os(iOS)
#if os(iOS) || os(visionOS)
import UIKit
#endif

Expand Down Expand Up @@ -44,7 +44,7 @@ class PlatformContext {
self.mobileDictUpdateFrequency = mobileDictUpdateFrequency
self.networkDictUpdateFrequency = networkDictUpdateFrequency
self.deviceInfoMonitor = deviceInfoMonitor
#if os(iOS)
#if os(iOS) || os(visionOS)
UIDevice.current.isBatteryMonitoringEnabled = true
#endif
setPlatformDict()
Expand All @@ -53,7 +53,7 @@ class PlatformContext {
/// Updates and returns payload dictionary with device context information.
/// - Parameter userAnonymisation: Whether to anonymise user identifiers (IDFA values)
func fetchPlatformDict(userAnonymisation: Bool, advertisingIdentifierRetriever: (() -> UUID?)?) -> Payload {
#if os(iOS)
#if os(iOS) || os(visionOS)
let now = Date().timeIntervalSince1970
if now - lastUpdatedEphemeralMobileDict >= mobileDictUpdateFrequency {
setEphemeralMobileDict()
Expand Down Expand Up @@ -87,7 +87,7 @@ class PlatformContext {
platformDict[kSPPlatformDeviceManu] = deviceInfoMonitor.deviceVendor
platformDict[kSPPlatformDeviceModel] = deviceInfoMonitor.deviceModel

#if os(iOS)
#if os(iOS) || os(visionOS)
setMobileDict()
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Tracker/Tracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class Tracker: NSObject {
super.init()
builder(self)

#if os(iOS)
#if os(iOS) || os(visionOS)
platformContextSchema = kSPMobileContextSchema
#else
platformContextSchema = kSPDesktopContextSchema
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Tracker/WebViewMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import Foundation

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS)
import WebKit

/// Handler for messages from the JavaScript library embedded in Web views.
Expand Down
16 changes: 9 additions & 7 deletions Sources/Core/Utils/DeviceInfoMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import WatchKit
#if os(iOS)
import CoreTelephony
#endif
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit
#endif

Expand All @@ -28,7 +28,7 @@ class DeviceInfoMonitor {
/// Returns the generated identifier for vendors. More info can be found in UIDevice's identifierForVendor documentation.
/// - Returns: A string containing a formatted UUID for example E621E1F8-C36C-495A-93FC-0C247A3E6E5F.
var appleIdfv: String? {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
if let idfv = UIDevice.current.identifierForVendor?.uuidString {
return idfv
}
Expand Down Expand Up @@ -60,7 +60,7 @@ class DeviceInfoMonitor {
/// This is to detect what the version of mobile OS of the current device.
/// - Returns: The current device's OS version type as a string.
var osVersion: String? {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
return UIDevice.current.systemVersion
#elseif os(watchOS)
return WKInterfaceDevice.current().systemVersion
Expand All @@ -85,6 +85,8 @@ class DeviceInfoMonitor {
return "tvos"
#elseif os(watchOS)
return "watchos"
#elseif os(visionOS)
return "visionos"
#else
return "osx"
#endif
Expand Down Expand Up @@ -146,7 +148,7 @@ class DeviceInfoMonitor {
/// Returns the Network Type the device is connected to.
/// - Returns: A string containing the Network Type.
var networkType: String? {
#if os(iOS)
#if os(iOS) || os(visionOS)
let networkStatus = SNOWReachability.forInternetConnection()?.networkStatus
switch networkStatus {
case .offline:
Expand All @@ -165,7 +167,7 @@ class DeviceInfoMonitor {
/// Returns remaining battery level as an integer percentage of total battery capacity.
/// - Returns: Battery level.
var batteryLevel: Int? {
#if os(iOS)
#if os(iOS) || os(visionOS)
let batteryLevel = UIDevice.current.batteryLevel
if batteryLevel != Float(UIDevice.BatteryState.unknown.rawValue) && batteryLevel >= 0 {
return Int(batteryLevel * 100)
Expand All @@ -177,7 +179,7 @@ class DeviceInfoMonitor {
/// Returns battery state for the device.
/// - Returns: One of "charging", "full", "unplugged" or NULL
var batteryState: String? {
#if os(iOS)
#if os(iOS) || os(visionOS)
switch UIDevice.current.batteryState {
case .charging:
return "charging"
Expand All @@ -196,7 +198,7 @@ class DeviceInfoMonitor {
/// Returns whether low power mode is activated.
/// - Returns: Boolean indicating the state of low power mode.
var isLowPowerModeEnabled: Bool? {
#if os(iOS)
#if os(iOS) || os(visionOS)
return ProcessInfo.processInfo.isLowPowerModeEnabled
#else
return nil
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/Utils/SNOWReachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the Apache License Version 2.0 for the specific
// language governing permissions and limitations there under.

#if os(iOS)
#if os(iOS) || os(visionOS)
import Foundation
import SystemConfiguration

Expand Down Expand Up @@ -65,7 +65,7 @@ class SNOWReachability: NSObject {
return .offline
}

#if os(iOS)
#if os(iOS) || os(visionOS)
let isWWAN = (flags.rawValue & SCNetworkReachabilityFlags.isWWAN.rawValue) == SCNetworkReachabilityFlags.isWWAN.rawValue
if isWWAN {
return .wwan
Expand Down
6 changes: 3 additions & 3 deletions Sources/Core/Utils/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
// express or implied. See the Apache License Version 2.0 for the specific
// language governing permissions and limitations there under.

#if os(iOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit
#elseif os(macOS)
import AppKit
#elseif os(tvOS)
import UIKit
#elseif os(watchOS)
import WatchKit
#endif
Expand All @@ -40,6 +38,8 @@ class Utilities {
class var platform: DevicePlatform {
#if os(iOS)
return .mobile
#elseif os(visionOS)
return .headset
#else
return .desktop
#endif
Expand Down
Loading

0 comments on commit 4831e4d

Please sign in to comment.