CLLocationManager delegate method is not called in iOS4

Weird bug, easy solution. I ran into this when updating to SDK 4.0: CLLocationManager simply would not work on the simulator. The same problem existed in iPhone Simulator 3.1.3.

The solution is quite weird: turn on AirPort (Wi-Fi) on your Mac, and CLLocationManager starts working again — fetching Cupertino, or in my case a wide area of my country. My guess is that the location is estimated from the IP address (or nearby networks) of your connection.

Why this actually happened

Core Location on a real device combines GPS, Wi-Fi, and cellular triangulation. The simulator has no GPS radio, so it derives a location from the host Mac’s network context — which is exactly why a disabled AirPort left it with nothing to go on and delegate callbacks never fired.

Today: nobody needs the Wi-Fi trick

The Wi-Fi trick is a museum piece. Today you set the simulator’s location explicitly from the menu bar: Features → Location → Custom Location… (pre-Xcode 11.6 it lived under Debug). For anything non-trivial, add a GPX file to your scheme (Edit Scheme → Run → Options → Core Location) — a single <wpt> waypoint simulates a fixed position, and multiple timed waypoints simulate a route. Unit tests can drive it programmatically via XCUIDevice.shared.location. Apple documents all of this under Simulating location in tests.

And of course test on a real device when location actually matters — permission prompts, background updates, and accuracy behave nothing like the simulator.

4 thoughts on “CLLocationManager delegate method is not called in iOS4”

  1. Really? says:

    Really man? Where did you think the location would come from? The GPS chip in your mac? Of course you need internet connectivity to estimate location.

    Reply
    1. teliaz says:

      That’s funny. I did have connectivity, wired one!!! But it still needs to have the Airport open….
      That how it works in simulator in SDK 4.

      The app I was developing could manage to parse dynamic XML files downloaded asynchronous from web services (in simulator) having the Airport disabled. But the CLLocationManager needs the airport open. That’s the point of my post here.

      By the way … macbooks have this feature… !

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *