How to add custom message if location disabled from Privacy->Location Services -> off. I am using iPhone11 and getting apple issues as to add description about application if disabled also. Please suggest.
You can do something like this in your locationManager class.
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")
}
}
In function checkLocationServices() you can show alert to the user if CLLocationManager.locationServicesEnabled() returns false.