0

I already posted about this but the answer given did not solve my issue, though it does seem like better code than what I had previously, so I'm using it.

For some reason didUpdateLocations is not being called, even when I set the delegate to the view controller. Neither is the didFailWithError ever called, so it's not like I am even throwing an error. But I know that didChangeAuthorization is being called.

Also in info.plist I set the key Privacy - Location When In Use Usage Description to a description.

So I'm not sure what I could be doing wrong?

Code

import MapKit
import CoreLocation

class OptionsViewController: UIViewController, UITableViewDelegate, CLLocationManagerDelegate {
    override func viewDidLoad() {
                //Ask user for location
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    
    //Use users current location if no starting point set
    if CLLocationManager.locationServicesEnabled() {
        if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse
            || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways {
            locationManager.startUpdatingLocation()
        }
        else{
            locationManager.requestWhenInUseAuthorization()
        }
    }
    else{
        //Alert user to open location service, bra bra bra here...
    }
    }

    public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    if status == CLAuthorizationStatus.authorizedWhenInUse
        || status == CLAuthorizationStatus.authorizedAlways {
        locationManager.startUpdatingLocation()
    }
    else{
        //other procedures when location service is not permitted.
    }
    }

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){
    locationManager.stopUpdatingLocation()
    print("didFailWithError")
    print(error)
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    print("Did update location called?")
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    print("locations = \(locValue.latitude) \(locValue.longitude)")
}
}
Community
  • 1
  • 1
14wml
  • 4,048
  • 11
  • 49
  • 97
  • 1
    Please don't repost your question. If needed, edit your previous question with whatever additional details may be useful. – rmaddy Apr 19 '17 at 03:06
  • @rmaddy I would do that if people actually responded to my edits. Stackoverflow seems to dismiss questions that already have a responses even tho the user didn't mark those answers as correct – 14wml Apr 19 '17 at 03:15

0 Answers0