Hello,
I've implemented a button which locates user on map. I would also to inform user, when location sharing for this app is set to never, that user needs to turn it on in settings. Here are those functions:
func checkLocationServices() {
if CLLocationManager.locationServicesEnabled() {
checkLocationAuthorization()
} else {
// Show alert letting the user know they have to turn this on.
}
}
func checkLocationAuthorization() {
let manager = CLLocationManager()
switch manager.authorizationStatus {
case .authorizedWhenInUse:
mapView.showsUserLocation = true
case .denied: // Show alert telling users how to turn on permissions
break
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
mapView.showsUserLocation = true
case .restricted: // Show an alert letting them know what’s up
break
case .authorizedAlways:
break
@unknown default:
break
}
}
@IBAction func myLocationButtonTapped(_ sender: Any) {
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
}