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()
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter