Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // testViewController.swift
- // MagicChat
- //
- // Created by Ivan Divljak on 7/19/18.
- // Copyright © 2018 Mexonis. All rights reserved.
- //
- import UIKit
- class LocationViewController: UIViewController, CLLocationManagerDelegate {
- let locationManager = CLLocationManager()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.locationManager.requestAlwaysAuthorization()
- // For use in foreground
- self.locationManager.requestWhenInUseAuthorization()
- if CLLocationManager.locationServicesEnabled() {
- locationManager.delegate = self
- locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
- locationManager.startUpdatingLocation()
- }
- }
- func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
- print(error.localizedDescription)
- }
- func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
- if status == .authorizedWhenInUse {
- locationManager.requestLocation()
- }
- }
- func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
- //get current location
- if let location = locations.last {
- //radi sta hoces
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement