Whenever I try using the Map() object in swiftui it never asks for location permission and always gives these errors:
Compiler failed to build request
PSO error: Target OS is incompatible: library was not compiled for the simulator
[MKCoreLocationProvider] CLLocationManager(<CLLocationManager: 0x600003225400>) for <MKCoreLocationProvider: 0x60000022d170> did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)"
Here’s the code for the viewmodel:
final class ContentViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {
@Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 0, longitude: 0), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
var locationManager: CLLocationManager?
func isLocationEnabled() {
if CLLocationManager.locationServicesEnabled() {
locationManager = CLLocationManager()
locationManager!.delegate = self
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
checkAuth()
} else {
print("Show alert to user to turn on locaiton services.")
}
}
private func checkAuth() {
guard let locationManager = locationManager else {return}
switch locationManager.authorizationStatus {
case .notDetermined:
locationManager.requestAlwaysAuthorization()
case .restricted:
print("Send alert notifying user that their location is restricted")
case .denied:
print("Send alert saying we need their location to use our app")
case .authorizedAlways, .authorizedWhenInUse:
region = MKCoordinateRegion(center: locationManager.location!.coordinate, span:MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
@unknown default:
break
}
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
checkAuth()
}
}
If anyone knows what the issue is please let me know. I’ve been trying to figure this out for the past day. Thanks!
I didn’t try anything other than updating and redownloading the library for watchos. Loading onto my watch didn’t work either since the build kept failing because it couldn’t download and it was overall a headache to keep trying
I was expecting for a map that follows the users location to show up. But it didn’t happen.