title: How to force 'always' location access in iOS app
body: <p>The app that I'm building needs always location access to work properly. The app basically tracks location and puts it on a map and stuff (details not important, lol).</p>
  <p>My goal is this:</p>
  <ol>
  <li>Prompt user to enable &quot;always&quot; location access</li>
  <li>If always location access has been requested but the user said no, make the app unusable - basically just show a little button that redirects them to settings where they can change that setting.</li>
  </ol>
  <p>My AppDelegate.swift is implementing CLLocationManagerDelegate, and the code is as follows:</p>
  <pre><code>alreadyRequestedLocationWhenInUse = UserDefaults.standard.bool(forKey: &quot;alreadyRequestedLocationWhenInUse&quot;)
  alreadyRequestedLocationAlways = UserDefaults.standard.bool(forKey: &quot;alreadyRequestedLocationAlways&quot;)
  
          func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
        
          switch CLLocationManager.authorizationStatus() {
          case .notDetermined:
              if (!alreadyRequestedLocationWhenInUse) {
                  print(&quot;Requesting location access 'while in use'.&quot;)
                  self.locationManager.requestWhenInUseAuthorization();
                  UserDefaults.standard.set(true, forKey: &quot;alreadyRequestedLocationWhenInUse&quot;)
                  alreadyRequestedLocationWhenInUse = true
              } else {
                  promptToChangeLocationSettings()
              }
          case .restricted, .denied:
              print(&quot;No Location access&quot;)
              promptToChangeLocationSettings()
              break;
          case .authorizedWhenInUse:
              if (!alreadyRequestedLocationAlways) {
                  print(&quot;Requesting location access 'Always'.&quot;)
                  self.locationManager.requestAlwaysAuthorization()
                  UserDefaults.standard.set(true, forKey: &quot;alreadyRequestedLocationAlways&quot;)
                  alreadyRequestedLocationAlways = true
              } else {
                  promptToChangeLocationSettings()
              }
              break;
          case .authorizedAlways:
              self.startLocationMonitoring();
              break;
          default:
              self.locationManager.requestAlwaysAuthorization();
              return
          }
      }
  </code></pre>
  <p>where promptToChangeLocationSettings() is a properly working function that takes the user to the settings page for my app.</p>
  <p>The problem is that the user isn't prompted to enable &quot;Always location tracking&quot; until they exit the app and come back. They are asked for 'while in use' permissions (and I know that the way it works is they have to say yes to that first), but I want the always prompt to happen right away! In theory, the locationManagerDidChangeAuthorization function should be called AGAIN after the 'while use' authorization is granted, but this does not happen! Why does this not happen? Instead, promptUserToChangeLocationSettings() runs and makes the app unusable BEFORE the user gets the little poup that asks whether they want to enable 'always' location access.</p>
  <p>Can someone help me fix this?
  By the way, I am using UserDefaults to keep track of whether we have done a location permission request (as the request can only be done once).</p>