-1

I have the following code:

import CoreLocation

class ViewController: UIViewController, NetworkingDelegate, CLLocationManagerDelegate {
    let locationManager: CLLocationManager = CLLocationManager()

and then later:

 locationManager.delegate = self
 locationManager.desiredAccuracy = kCLLocationAccuracyBest
 locationManager.requestWhenInUseAuthorization()
 locationManager.startUpdatingLocation()

and then I implement the delegate methods lower in the VC

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

        for currentLocation in locations{
            print("\(index)\(currentLocation)")
        }
        print("Did Location Delegate get called?")
        let location: CLLocation = locations.first as! CLLocation
        print(location)
        self.lat = String(format: "%f", location.coordinate.latitude)
        self.long = String(format: "%f", location.coordinate.longitude)
        }

In build phases, "Link Binary With Libraries" has CoreLocation.framework selected.

The proper privacy in plist is present: Privacy - Location Usage Description as is Privacy - Location When In Use Usage Description.

The location is still not being gotten. I am using simulator in Xcode 9.4.1 targeting iOS 11. What am I missing here?

noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52
  • **YOU MUST TURN ON LOC. IN XCODE SIMULATOR OPTIONS!!** so annoying. https://stackoverflow.com/a/32887820/294884 – Fattie May 27 '19 at 01:28

1 Answers1

0

The problem is that func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) is years out of date. Update your code for modern Swift. Here's how the declaration should look:

https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1423615-locationmanager

matt
  • 515,959
  • 87
  • 875
  • 1,141