Skip to content

Commit

Permalink
visionOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
lowip committed Jul 8, 2024
1 parent 914f81a commit d5b0c83
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let package = Package(
.macOS(.v10_15),
.tvOS(.v13),
.watchOS(.v6),
.visionOS(.v1),
],
products: [
.library(
Expand Down
8 changes: 8 additions & 0 deletions Sources/ComposableCoreLocation/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,23 @@ public struct LocationManager: DependencyKey {

@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didDetermineState(CLRegionState, region: Region)

@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didEnterRegion(Region)

@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didExitRegion(Region)

@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didFailRanging(beaconConstraint: CLBeaconIdentityConstraint, error: Error)

case didFailWithError(Error)
Expand All @@ -217,6 +221,7 @@ public struct LocationManager: DependencyKey {

@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didStartMonitoring(region: Region)

@available(macOS, unavailable)
Expand All @@ -232,15 +237,18 @@ public struct LocationManager: DependencyKey {
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didVisit(Visit)

@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case monitoringDidFail(region: Region?, error: Error)

@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
case didRangeBeacons([Beacon], satisfyingConstraint: CLBeaconIdentityConstraint)
}

Expand Down
50 changes: 30 additions & 20 deletions Sources/ComposableCoreLocation/Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ extension LocationManager {
return nil
},
authorizationStatus: {
#if (compiler(>=5.3) && !(os(macOS) || targetEnvironment(macCatalyst))) || compiler(>=5.3.1)
if #available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, macCatalyst 14.0, *) {
return manager.authorizationStatus
}
#if os(visionOS)
return manager.authorizationStatus
#else
#if (compiler(>=5.3) && !(os(macOS) || targetEnvironment(macCatalyst))) || compiler(>=5.3.1)
if #available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, macCatalyst 14.0, *) {
return manager.authorizationStatus
}
#endif
return CLLocationManager.authorizationStatus()
#endif
return CLLocationManager.authorizationStatus()
},
delegate: { delegateStream },
dismissHeadingCalibrationDisplay: {
Expand All @@ -55,14 +59,14 @@ extension LocationManager {
#endif
},
headingAvailable: {
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst) || os(visionOS)
return CLLocationManager.headingAvailable()
#else
return false
#endif
},
isRangingAvailable: {
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst) || os(visionOS)
return CLLocationManager.isRangingAvailable()
#else
return false
Expand Down Expand Up @@ -93,7 +97,7 @@ extension LocationManager {
manager.requestLocation()
},
requestWhenInUseAuthorization: {
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst) || os(visionOS)
manager.requestWhenInUseAuthorization()
#endif
},
Expand All @@ -111,7 +115,7 @@ extension LocationManager {
manager.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates
}
#endif
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || targetEnvironment(macCatalyst) || os(visionOS)
if let desiredAccuracy = properties.desiredAccuracy {
manager.desiredAccuracy = desiredAccuracy
}
Expand All @@ -127,7 +131,7 @@ extension LocationManager {
manager.headingOrientation = headingOrientation
}
#endif
#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || os(visionOS)
if let pausesLocationUpdatesAutomatically = properties
.pausesLocationUpdatesAutomatically
{
Expand All @@ -139,7 +143,7 @@ extension LocationManager {
#endif
},
significantLocationChangeMonitoringAvailable: {
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst) || os(visionOS)
return CLLocationManager.significantLocationChangeMonitoringAvailable()
#else
return false
Expand All @@ -166,7 +170,7 @@ extension LocationManager {
#endif
},
startUpdatingLocation: {
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst) || os(visionOS)
manager.startUpdatingLocation()
#endif
},
Expand All @@ -191,7 +195,7 @@ extension LocationManager {
#endif
},
stopUpdatingLocation: {
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst) || os(visionOS)
manager.stopUpdatingLocation()
#endif
}
Expand All @@ -206,12 +210,18 @@ private class LocationManagerDelegate: NSObject, CLLocationManagerDelegate {
self.continuation = continuation
}

func locationManager(
_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus
) {
self.continuation.yield(.didChangeAuthorization(status))
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
self.continuation.yield(.didChangeAuthorization(manager.authorizationStatus))
}

#if !os(visionOS)
func locationManager(
_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus
) {
self.continuation.yield(.didChangeAuthorization(status))
}
#endif

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
self.continuation.yield(.didFailWithError(LocationManager.Error(error)))
}
Expand All @@ -234,7 +244,7 @@ private class LocationManagerDelegate: NSObject, CLLocationManagerDelegate {
}
#endif

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst) || os(visionOS)
func locationManager(
_ manager: CLLocationManager, didFinishDeferredUpdatesWithError error: Error?
) {
Expand All @@ -244,13 +254,13 @@ private class LocationManagerDelegate: NSObject, CLLocationManagerDelegate {
}
#endif

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || os(visionOS)
func locationManagerDidPauseLocationUpdates(_ manager: CLLocationManager) {
self.continuation.yield(.didPauseLocationUpdates)
}
#endif

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || os(visionOS)
func locationManagerDidResumeLocationUpdates(_ manager: CLLocationManager) {
self.continuation.yield(.didResumeLocationUpdates)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/ComposableCoreLocation/Models/Beacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CoreLocation
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public struct Beacon: Hashable {
public var accuracy: CLLocationAccuracy
public var major: NSNumber
Expand Down
1 change: 1 addition & 0 deletions Sources/ComposableCoreLocation/Models/Heading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct Heading: Hashable {
@available(iOS 3, macCatalyst 13, watchOS 2, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(visionOS, unavailable)
public init(rawValue: CLHeading) {
self.headingAccuracy = rawValue.headingAccuracy
self.magneticHeading = rawValue.magneticHeading
Expand Down
9 changes: 6 additions & 3 deletions Sources/ComposableCoreLocation/Models/Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import CoreLocation
/// A value type wrapper for `CLRegion`. This type is necessary so that we can do equality checks
/// and write tests against its values.
public struct Region: Hashable {
public let rawValue: CLRegion?
@available(visionOS, unavailable)
public var rawValue: CLRegion? { _rawValue as? CLRegion }
private let _rawValue: Any?

public var identifier: String
public var notifyOnEntry: Bool
public var notifyOnExit: Bool

@available(visionOS, unavailable)
public init(rawValue: CLRegion) {
self.rawValue = rawValue
self._rawValue = rawValue

self.identifier = rawValue.identifier
self.notifyOnEntry = rawValue.notifyOnEntry
Expand All @@ -22,7 +25,7 @@ public struct Region: Hashable {
notifyOnEntry: Bool,
notifyOnExit: Bool
) {
self.rawValue = nil
self._rawValue = nil

self.identifier = identifier
self.notifyOnEntry = notifyOnEntry
Expand Down
1 change: 1 addition & 0 deletions Sources/ComposableCoreLocation/Models/Visit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CoreLocation
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public struct Visit: Hashable {
public let rawValue: CLVisit?

Expand Down

0 comments on commit d5b0c83

Please sign in to comment.