Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.38 KB | None | 0 0
  1. //
  2. //  testViewController.swift
  3. //  MagicChat
  4. //
  5. //  Created by Ivan Divljak on 7/19/18.
  6. //  Copyright © 2018 Mexonis. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class LocationViewController: UIViewController, CLLocationManagerDelegate {
  12.    
  13.    
  14.     let locationManager = CLLocationManager()
  15.    
  16.    
  17.     override func viewDidLoad() {
  18.         super.viewDidLoad()
  19.         self.locationManager.requestAlwaysAuthorization()
  20.         // For use in foreground
  21.         self.locationManager.requestWhenInUseAuthorization()
  22.        
  23.         if CLLocationManager.locationServicesEnabled() {
  24.             locationManager.delegate = self
  25.             locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
  26.             locationManager.startUpdatingLocation()
  27.         }
  28.     }
  29.    
  30.    
  31.     func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
  32.         print(error.localizedDescription)
  33.     }
  34.    
  35.     func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
  36.         if status == .authorizedWhenInUse {
  37.             locationManager.requestLocation()
  38.         }
  39.     }
  40.    
  41.     func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  42.         //get current location
  43.         if let location = locations.last {
  44.             //radi sta hoces
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement