title: Trying to get location permission in iOS Swift
body: <p>I'm working on a button that will send the user to the maps application if he grants the app location permission. The problem is that if I click the button once and decline location permission, the next time I'm clicking the button the app doesn't ask for permission again. Seems like the user have "only one shot at granting maps permission". </p>
  
  <p>Below is the code I use to programmatically create the button with the callback functions. There's also a screenshot of the "Custom iOS Target Properties" where I have included the Privacy - Location Usage Description to be able to use users location.</p>
  
  <pre><code>directionsButton.addTarget(self, action: #selector(getDirection), for:   UIControlEvents.touchUpInside)
  
  
  func getDirection(sender: UIButton!) {
      print("1")
      if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
          CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){
         let url = URL(string: "http://maps.apple.com/?daddr=60.79281049999999,10.688968899999963")
         if (UIApplication.shared.canOpenURL(url!)) {
              UIApplication.shared.openURL(url!)
          } else {
              print("Error")
          }
          print("2")
      } else{
          LocationManager.requestWhenInUseAuthorization()
          print("3")
      }
      print("4")
  }
  
  /*
   - Callback function for changes in location permissions
   */
  func locationManager(_ manager: CLLocationManager,
  didChangeAuthorization status: CLAuthorizationStatus){
      print("change in auth")
      if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse){
          let url = URL(string: "http://maps.apple.com/?daddr=60.79281049999999,10.688968899999963")
          if (UIApplication.shared.canOpenURL(url!)) {
              UIApplication.shared.openURL(url!)
          } else {
              print("Error")
          }
      } else{
          self.view.makeToast("Couldn't get location permission", duration: 3.0, position: .bottom)
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9bNEZ.png" rel="nofollow noreferrer">Picture of permissions added in the info-file</a></p>