My app wants to trace the consumer’s location however every time my locationManager
sends a location replace, it dismisses a toolbar menu (whether it is displayed). The odd factor is that if the menu buttons have empty actions or only a print assertion then all is ok however as quickly as a technique is put in there it dismisses upon the following UI replace.
iOS: 17.0
Xcode: Model 15.0 beta 3
Background Modes: Location updates
Privateness – Location When In Use Utilization Description = You’re being watched!
import SwiftUI
@primary
struct DetectHelpApp: App {
var locationManager = LocationManager()
var physique: some Scene {
WindowGroup {
ContentView()
.surroundings(locationManager)
}
}
}
import MapKit
struct ContentView: View {
@Atmosphere(LocationManager.self) var locationManager
@State non-public var cameraPosition: MapCameraPosition = .area(MKCoordinateRegion(middle: CLLocationCoordinate2D(latitude: 51.556000, longitude: -0.279511), latitudinalMeters: 1000, longitudinalMeters: 1000))
var physique: some View {
NavigationStack {
Map(place: $cameraPosition) {
UserAnnotation()
}
.onChange(of: locationManager.lastLocation) { oldValue, newValue in
print(locationManager.lastLocation)
withAnimation() {
cameraPosition = .area(MKCoordinateRegion(middle: newValue.coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000))
}
} // onChange - finish
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Menu("Menu") {
Button("Begin") { assist() /*print("Begin")*/ } // <-- *** HERE ***
Button("Resume") { print("Resume") }
}
}
}
.navigationTitle("Scooby Doo")
}
}
func assist() { }
}
import CoreLocation
import Commentary
@Observable
remaining class LocationManager: NSObject, CLLocationManagerDelegate {
var lastLocation: CLLocation = CLLocation(latitude: 51.556000, longitude: -0.279511)
let locationManager = CLLocationManager()
init(canine: String = "") {
tremendous.init()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 2
locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ supervisor: CLLocationManager, didUpdateLocations places: [CLLocation]) {
// Guarantee we now have an precise location within the replace.
guard let location = places.final else { return }
lastLocation = location // Our revealed CLLocation.
}
}