Skip to content

Instantly share code, notes, and snippets.

@davidseek
Last active September 5, 2018 17:35
Show Gist options
  • Select an option

  • Save davidseek/d519a1025522f90dc25dae28e83841f9 to your computer and use it in GitHub Desktop.

Select an option

Save davidseek/d519a1025522f90dc25dae28e83841f9 to your computer and use it in GitHub Desktop.
import Foundation
import CoreLocation
class LocationManager: NSObject {
private let locationManager = CLLocationManager()
override init() {
super.init()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
}
}
// MARK: - Core Location Delegate
extension LocationManager: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager,
didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .notDetermined : print("notDetermined") // location permission not asked for yet
case .authorizedWhenInUse : print("authorizedWhenInUse") // location authorized
case .authorizedAlways : print("authorizedAlways") // location authorized
case .restricted : print("restricted") // TODO: handle
case .denied : print("denied") // TODO: handle
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment