CLLocation Services question

Hi,
I have a dilemma. On an app I’m developing, I am trying to get the current location to show up as the blue dot. I have built the code the same way we did in the Guidebook app. My code steps through the following case statement and exits at the notDetermined case. When I go to location services on my phone, the “Location” entry is not in the list for the app and I have added the Privacy - Location When In Use Usage Description and Privacy - Location Always and When In Use Usage Description to the plist. Any suggestions?

func checkAuthorizationStatus() {
switch CLLocationManager.authorizationStatus() {
case .authorizedWhenInUse:
mapView.showsUserLocation = true
case .denied:
showGeolocationError()
case .notDetermined:
showGeolocationError()
case .restricted:
mapView.showsUserLocation = true
case .authorizedAlways:
mapView.showsUserLocation = true
@unknown default:
showGeolocationError()
}
}

Hi @nelsom17

Try this, I think you need to establish a location services are enabled first:

//Check if location services are enabled.
        if CLLocationManager.locationServicesEnabled() {
            
            //Check authoirization status
            let status = CLLocationManager.authorizationStatus()
            
            if status == .denied || status == .restricted {
                
                // show the error alert
                showGeoLocationError()
                
            } else if status == .authorizedWhenInUse || status == .authorizedAlways {
                
                // Geolocate user
                locationManager?.startUpdatingLocation()
                
                // Cneter the map around the user
                if let lastKnownLocation = lastKnownLocation {
                    mapView.setCenter(lastKnownLocation.coordinate, animated: true)
                }
                
            } else if status == .notDetermined {
                
                // TODO: Ask the user for permission
                locationManager?.requestWhenInUseAuthorization()
            }
        } else {
            
           // show alert asking for permission
            showGeoLocationError()
        }

Blessings,
—Mark

Thanks Mark,
I needed the requestWhenInUseAuthorization method. I had everything else but missed that.

Regards,
Mike