LocationCollector
public class LocationCollector : NSObject, DeviceCollector, @unchecked Sendable
Collector for device geographic location information.
This collector attempts to determine the device’s current location using the LocationManager system. It handles authorization requests and provides location data when available and permitted.
Privacy Considerations
Requires
Requires location permissions from the user- Respects user privacy settings and restrictions
Usage Requirements
- App must include location usage descriptions in Info.plist
- User must grant location permissions
- Location services must be enabled on device
-
Declaration
Swift
public typealias DataType = LocationInfo -
Unique identifier for location data
Declaration
Swift
public let key: String -
Initializes the collector with optional dependency injection
Declaration
Swift
public init(locationManager: LocationManager? = nil)Parameters
locationManagerLocationManager instance (defaults to shared)
-
collect()AsynchronousCollects current device location information
Behavior
- Requests location permission if not already granted
- Uses cached location if recently obtained
- Handles all authorization states appropriately
Error Handling
- Catches and handles all location-related errors internally
- Logs errors for debugging purposes
Declaration
Swift
public func collect() async -> LocationInfo?Return Value
LocationInfo with coordinates, or nil if location unavailable
View on GitHub