Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import CoreLocation
  2.  
  3. class ViewController: UIViewController, UITextFieldDelegate, CLLocationManagerDelegate {
  4.  
  5. var locationManager:CLLocationManager = CLLocationManager()
  6.  
  7.  
  8.  
  9. override func viewDidLoad() {
  10. super.viewDidLoad()
  11.  
  12.  
  13. self.locationManager.delegate = self
  14. locationManager.desiredAccuracy = kCLLocationAccuracyBest
  15. locationManager.requestAlwaysAuthorization()
  16. locationManager.startUpdatingLocation()
  17.  
  18.  
  19. }
  20.  
  21. func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
  22. print("didChangeAuthorizationStatus")
  23.  
  24. switch status {
  25. case .NotDetermined:
  26. print(".NotDetermined")
  27. break
  28.  
  29. case .Authorized:
  30. print(".Authorized")
  31. self.locationManager.startUpdatingLocation()
  32. break
  33.  
  34. case .Denied:
  35. print(".Denied")
  36. break
  37.  
  38. default:
  39. print("Unhandled authorization status")
  40. break
  41.  
  42. }
  43. }
  44.  
  45. func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  46.  
  47. let location = locations.last as CLLocation!
  48.  
  49. print("didUpdateLocations: (location.coordinate.latitude), (location.coordinate.longitude)")
  50.  
  51.  
  52. }
  53.  
  54. didChangeAuthorizationStatus
  55. .NotDetermined
  56.  
  57. <key>NSLocationAlwaysUsageDescription</key>
  58. <string>Your message goes here</string>
  59. <key>NSLocationWhenInUseUsageDescription</key>
  60. <string>Your message goes here</string>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement