Вы можете сделать что-то подобное в своем классе locationManager.
func checkLocationServices() {
if CLLocationManager.locationServicesEnabled() {
setupLocationManager()
checkLocationAuthorization()
} else {
// Show alert letting the user know they have to turn this on.
self.delegate?.showLocationServiceDialog(status: 2)
}
}
func checkLocationAuthorization() {
switch CLLocationManager.authorizationStatus() {
case .authorizedWhenInUse:
locationManager?.startUpdatingLocation()
break
case .denied:
//I'm sorry - I can't show location. User has not authorized it
self.delegate?.showLocationPermissionDialog(status: 0)
break
case .notDetermined:
locationManager!.requestAlwaysAuthorization()
case .restricted:
// Access to Location Services is Restricted", message: "Parental Controls or a system administrator may be limiting your access to location services. Ask them to.
self.delegate?.showLocationPermissionDialog(status: 1)
break
case .authorizedAlways:
locationManager?.startUpdatingLocation()
break
@unknown default:
print("Unknown permission status")
}
}
В функции checkLocationServices () вы можете показывать предупреждение пользователю, если CLLocationManager.locationServicesEnabled () возвращает false.