Contents

swiftuiux/swift-async-corelocation-streamer

This package uses Core Location under the hood to harness the power of GPS for accurate and efficient location tracking. By leveraging Swift’s async/await concurrency model, it provides a modern, clean, and scalable way to stream GPS data asynchronously. Core Location works with

[SwiftUI example](https://github.com/swiftuiux/corelocation-manager-tracker-swift-apple-maps-example)

Available for watchOS

[simulate locations]

if you are using the simulator don't forget to simulate locations

[simulate locations]

## Features

  • [x] Using new concurrency swift model around CoreLocation manager
  • [x] Extend API to allow customization of CLLocationManager
  • [x] Support for iOS from 14.1 and watchOS from 7.0
  • [x] Seamless SwiftUI Integration Uses @Published properties for real-time UI updates or @observable is you can afford iOS17 or newer.
  • [x] Streaming current location asynchronously
  • [x] Different strategies - Keep and publish all stack of locations since streaming has started or the last one
  • [x] Errors handling (as AsyncLocationErrors so CoreLocation errors CLError)

How to use

1. Add to info the option "Privacy - Location When In Use Usage Description"

[Add to info]

Background Updates - Ensure the app has location included in UIBackgroundModes for background updates to function.

2. Add or inject LocationStreamer into a View

    @StateObject var service: LocationStreamer 

For iOS 17+ and watchOS 10+, using @State macro:

    @State var service: ObservableLocationStreamer

3. Call LocationStreamer method start() within async environment or check SwiftUI example

    try await service.start()

LocationStreamer parameters

|Param|Description| | --- | --- | |strategy| Strategy for publishing locations. Default value is KeepLastStrategy. Another predefined option is KeepAllStrategy, or you can implement and test your own custom strategy by conforming to the LocationResultStrategy protocol. | |accuracy| The accuracy of a geographical coordinate.| |activityType| Constants indicating the type of activity associated with location updates.| |distanceFilter| A distance in meters from an existing location to trigger updates.| |backgroundUpdates| A Boolean value that indicates whether the app receives location updates when running in the background. |

or

|Param|Description| | --- | --- | |strategy| Strategy for publishing locations. Default value is KeepLastStrategy. Another predefined option is KeepAllStrategy, or you can implement and test your own custom strategy by conforming to the LocationResultStrategy protocol. | |locationManager| A pre-configured CLLocationManager. |

Default location

  1. Product > Scheme > Edit Scheme
  2. Click Run .app
  3. Option tab
  4. Already checked Core Location > select your location
  5. Press OK

[Default location]

Documentation(API)

  • You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
  • Go to Product > Build Documentation or ⌃⇧⌘ D

Package Metadata

Repository: swiftuiux/swift-async-corelocation-streamer

Default branch: main

README: README.md