2

I have an app where I leverage CoreLocation. For some reason when I use Xcode 9 or even the 9.1 beta 2, setting custom location coordinates under Debug > Locations > Custom Location in the iPhone simulator doesn't work as expected.

When I apply the custom coordinates, didUpdateLocations is only called once, or three times, then the location services turn off, and the location arrow turns into an outline. I know most of you guys will say that I shouldn't be testing location services on the simulator, but I do not have a choice, as I do not have access to a device at the moment.

I have provided some simple code bellow for accessing the users location and update it continuously. If you could, please test this out on your iPhone simulator in Xcode 9+ (ios 11+) and set a custom latitude and longitude to Debug > Locations > Custom Location and see if you get the same issue.

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

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

    } 

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.first {
            print(location.coordinate)
        }
    }

}
Julian
  • 77
  • 6
  • Possible duplicate? https://stackoverflow.com/questions/24368866/ios-cllocationmanager-receives-location-update-only-once-in-didupdatelocations – Claudio Castro Oct 24 '17 at 20:39
  • Sadly, none of those solutions are applicable @Claudio – Julian Oct 24 '17 at 20:42
  • I put the three privacy - location keys in the plist and executed your code, whenever I changed the custom location the new coordinate was printed. How are you testing? – Claudio Castro Oct 24 '17 at 20:57
  • huh interesting @Claudio, I also have the three privacy keys in my plist. I'm using the iPhone X, 8, 8 plus, and the 7 simulators. One weird thing I noticed is that if I set the location to Apple, city run, etc in the debug location it works like normal and updates the location every second. When I set it to any custom location it works for a second then stops – Julian Oct 24 '17 at 22:25
  • 1
    Same here, but note that didupdatelocation only fire when location change. So, this is the normal work. https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1423615-locationmanager?language=objc – Claudio Castro Oct 24 '17 at 22:36
  • Oh true, I didn't know that. Thank you for your help. – Julian Oct 24 '17 at 22:39

0 Answers0