import UIKit
import CoreLocation
class ViewController: UIViewController{
//...
}
extensiion ViewController: CLLocationManagerDelegate{
func checkLocationAuthorization(){
switch locationManager.authorizationStatus {
case .authorizedWhenInUse:
// do GPS location stuff
getUserCoordinates()
locationManager.startUpdatingLocation()
break
case .denied:
// Show an alert instructing user how to turn on permission
break
case.notDetermined:
locationManager.requestWhenInUseAuthorization()
break
case .restricted:
// Show an alert instructing user how to turn on permission
break
default:
break
}
}
//...
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
checkLocationAuthorization()
}
}