Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import CoreLocation
- class ViewController: UIViewController, UITextFieldDelegate, CLLocationManagerDelegate {
- var locationManager:CLLocationManager = CLLocationManager()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.locationManager.delegate = self
- locationManager.desiredAccuracy = kCLLocationAccuracyBest
- locationManager.requestAlwaysAuthorization()
- locationManager.startUpdatingLocation()
- }
- func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
- print("didChangeAuthorizationStatus")
- switch status {
- case .NotDetermined:
- print(".NotDetermined")
- break
- case .Authorized:
- print(".Authorized")
- self.locationManager.startUpdatingLocation()
- break
- case .Denied:
- print(".Denied")
- break
- default:
- print("Unhandled authorization status")
- break
- }
- }
- func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
- let location = locations.last as CLLocation!
- print("didUpdateLocations: (location.coordinate.latitude), (location.coordinate.longitude)")
- }
- didChangeAuthorizationStatus
- .NotDetermined
- <key>NSLocationAlwaysUsageDescription</key>
- <string>Your message goes here</string>
- <key>NSLocationWhenInUseUsageDescription</key>
- <string>Your message goes here</string>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement