Simulator Location Authorization Issue: Authorization Status Remains notDetermined After Denying and Changing in System Settings

Hello everyone,

I'm encountering a strange location authorization issue in the iOS simulator, and I'm hoping someone can help me analyze it.

Problem Description:

  1. When my app runs for the first time in the simulator, it requests location permissions.
  2. I select "Deny" for the authorization.
  3. Then, I go to the simulator's "Settings" -> "Privacy & Security" -> "Location Services" and enable location permissions for my app.
  4. However, when I return to the app, CLLocationManager.authorizationStatus still returns .notDetermined, and the authorization request pop-up does not appear again.
  5. This issue persists even after resetting the simulator settings multiple times.
import CoreLocation

@Observable
final class LocationManager: NSObject, CLLocationManagerDelegate {
   
   var locationManager = CLLocationManager()
   var currentLocation: CLLocationCoordinate2D?
   
   override init() {
      super.init()
      locationManager.delegate = self
   }
   
   func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
      let status = manager.authorizationStatus
      print("Authorize Status: \(status)")
      
      switch status {
      case .authorizedWhenInUse, .authorizedAlways:
         locationManager.startUpdatingLocation()
      case .denied, .restricted:
         stopLocation()
      case .notDetermined:
         locationManager.requestWhenInUseAuthorization()
         print("Location permission not determined.")
      @unknown default:
         break
      }
   }
   
   func requestLocation() {
      let status = locationManager.authorizationStatus
      if status == .authorizedWhenInUse || status == .authorizedAlways {
         locationManager.requestLocation()
      } else {
         locationManager.requestWhenInUseAuthorization()
      }
   }

   func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      guard let newLocation = locations.first else { return }
      currentLocation = newLocation.coordinate
      print("Updated location: \(newLocation.coordinate)")
   }
   
   func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
      print("Location update failed with error: \(error.localizedDescription)")
      currentLocation = nil
   }
   
   func stopLocation() {
      locationManager.stopUpdatingLocation()
      print("Stopped updating location")
   }
}
Simulator Location Authorization Issue: Authorization Status Remains notDetermined After Denying and Changing in System Settings
 
 
Q