mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Resume continuation
This commit is contained in:
parent
3e3f154a8e
commit
da40b4b0b2
2 changed files with 14 additions and 11 deletions
|
|
@ -10,14 +10,14 @@ import CoreLocation
|
|||
import OSLog
|
||||
|
||||
// Shared state that manages the `CLLocationManager` and `CLBackgroundActivitySession`.
|
||||
@MainActor class LocationsHandler: ObservableObject {
|
||||
@MainActor class LocationsHandler: NSObject, ObservableObject, @preconcurrency CLLocationManagerDelegate {
|
||||
|
||||
static let shared = LocationsHandler() // Create a single, shared instance of the object.
|
||||
public let manager: CLLocationManager
|
||||
public var manager = CLLocationManager()
|
||||
private var background: CLBackgroundActivitySession?
|
||||
var enableSmartPosition: Bool = UserDefaults.enableSmartPosition
|
||||
|
||||
@Published var locationsArray: [CLLocation]
|
||||
@Published var locationsArray: [CLLocation] = [CLLocation]()
|
||||
@Published var isStationary = false
|
||||
@Published var count = 0
|
||||
@Published var isRecording = false
|
||||
|
|
@ -39,18 +39,22 @@ import OSLog
|
|||
}
|
||||
}
|
||||
// The continuation we will use to asynchronously ask the user permission to track their location.
|
||||
var permissionContinuation: CheckedContinuation<CLAuthorizationStatus, Never>?
|
||||
private var permissionContinuation: CheckedContinuation<CLAuthorizationStatus, Never>?
|
||||
func requestLocationAlwaysPermissions() async -> CLAuthorizationStatus {
|
||||
self.manager.requestAlwaysAuthorization()
|
||||
return await withCheckedContinuation { continuation in
|
||||
permissionContinuation = continuation
|
||||
self.permissionContinuation = continuation
|
||||
manager.requestAlwaysAuthorization()
|
||||
}
|
||||
}
|
||||
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
||||
// This is the line you need to add
|
||||
permissionContinuation?.resume(returning: manager.authorizationStatus)
|
||||
}
|
||||
|
||||
private init() {
|
||||
self.manager = CLLocationManager() // Creating a location manager instance is safe to call here in `MainActor`.
|
||||
override init() {
|
||||
super.init()
|
||||
self.manager.delegate = self
|
||||
self.manager.allowsBackgroundLocationUpdates = true
|
||||
locationsArray = [CLLocation]()
|
||||
}
|
||||
|
||||
func startLocationUpdates() {
|
||||
|
|
|
|||
|
|
@ -174,10 +174,8 @@ struct DeviceOnboarding: View {
|
|||
Button {
|
||||
Task {
|
||||
await requestLocationPermissions()
|
||||
|
||||
}
|
||||
UserDefaults.firstLaunch = false
|
||||
dismiss()
|
||||
} label: {
|
||||
Text("Configure Location Permissions")
|
||||
.frame(maxWidth: .infinity)
|
||||
|
|
@ -282,5 +280,6 @@ struct DeviceOnboarding: View {
|
|||
} else {
|
||||
Logger.services.info("Notification permissions denied")
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue