41

CLLocationManager on iPhone Simulator is supposed to fake Cupertino (isn't it?) but it does NOT, it fails with kCLErrorDomain Code=0 instead. LocationManager's delegate receives the message didFailWithError. This method is implemented to log the error and the console outputs the following:

Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

I was working on a real project when I ran into this problem but it is pointless to discuss my code because I downloaded "Locations" sample code (updated 2010-06-22 for iOS 4) from the dev center and the problem persisted.

The app is suposed to enable an "add" button when it receives the first location update so users can track their locations but it does nothing.

I added one (trivial) line to the implementation of didFailWithError to log the errors, if any. I get the error described above.

With Xcode 3.2.2 and targeting 3.1.3, I could get a fixed location (Cupertino) when running an older version of the "Locations" project.

Can somebody help?

Thanks.

sKhan
  • 9,694
  • 16
  • 55
  • 53
albertamg
  • 28,492
  • 6
  • 64
  • 71
  • Im having exactly the same problem since upgrading to sdk 4 – Anthony Main Jun 24 '10 at 17:05
  • Have you opened your project by any chance with XCode 4.2 beta ? – Nicu Surdu Oct 07 '11 at 14:02
  • @Nicolae Surdu It's been a while since I posted this question... Indeed, it started to work when I recently upgraded to XCode 4.2 and the iOS Simulator 5.0 that comes with it. I explained my experience in an answer below. – albertamg Oct 20 '11 at 18:28
  • I've noticed that sometimes the simulator forgets your location preference. My recommendations: edit the run scheme and disable (uncheck) location simulation per @shafkhan's answer and then run your app on the simulator. Once your app loads go to debug > location and select Apple or one of the moving routes like City Run. – earnshavian Apr 08 '14 at 14:17

13 Answers13

64

This error also occurs if you have Scheme/Edit Scheme/Options/Allow Location Simulation checked but don't have a default location set.

Please check this it may resolve your issue.

sKhan
  • 9,694
  • 16
  • 55
  • 53
  • 1
    this did it for me. it was set to None in my project. – blueether Aug 11 '14 at 04:16
  • 1
    Profoundly annoying gotcha :(. Thanks! – OneChillDude Dec 04 '14 at 00:32
  • Was getting this error message in an Ionic / Cordova / PhoneGap app. Without knowing anything related to `Scheme/Edit Scheme/Options/Allow Location Simulation`, the fix for me was mostly the same: In the simulator itself, choose a location under `Debug > Location`. – kentr Apr 26 '16 at 21:26
19

Following Steps fixed my problem:

  1. Under the Simulator menu: Reset Content and Settings....
  2. Close the simulator
  3. Restart your app.
sKhan
  • 9,694
  • 16
  • 55
  • 53
Zak
  • 191
  • 1
  • 3
  • This worked for me! Now I have Scheme/Edit Scheme/Options/Allow Location Simulation checked, Default Location set to None in the Scheme Options, but Location set to Custom Location in the Debug menu/Location of the simulator. – Giuseppe Galano Sep 24 '15 at 12:48
10

I faced same situation and have followed this steps, may be it helps:)

1) Go to Simulator (whichever version)

2) Go to Debug menu -> Location -> Select Apple as your custom location.

it started working in my case..

sKhan
  • 9,694
  • 16
  • 55
  • 53
Shefali Soni
  • 1,234
  • 14
  • 26
7

This error also occurs if you have Scheme/Edit Scheme/Options/Allow Location Simulation checked but don't have a default location set.

sKhan
  • 9,694
  • 16
  • 55
  • 53
Hemang
  • 26,840
  • 19
  • 119
  • 186
  • Good tip @Hemang, helped me out. I had this issue, after updateing my scheme. Before my Simulator had a location set, but somehow this vanished. I had to re-enter the "custom location" and it worked fine. – jerik Aug 15 '13 at 07:00
7

I've heard this reported before but never saw it myself until just now. I had Airport turned off on my MacBook since I was using ethernet. I turned on Airport and restarted the simulator and now it works.

You need Wi-Fi (Airport) enabled on your Mac for the simulator to report a position with Xcode 3.2.3.

Community
  • 1
  • 1
progrmr
  • 75,956
  • 16
  • 112
  • 147
  • My Wi-Fi (Airport) is enabled and I still have the same problem. Maybe the simulator can't locate my Wi-Fi, do I need to register the location of my Wi-Fi at Skyhook? (See http://stackoverflow.com/questions/2140340/how-does-the-iphone-learn-new-wifi-locations-in-terms-of-using-them-for-location/2140499#2140499) – albertamg Jun 26 '10 at 09:27
  • I don't know, the simulator doesn't even use the WiFi, it always reports a fixed location in Cupertino anyway. Rather than spending a lot of time trying to fix it, you could just use this other solution: a [CLLocation simulator](http://stackoverflow.com/questions/802156/testing-corelocation-on-iphone-simulator) for use on the simulator. – progrmr Jun 26 '10 at 14:25
  • OK, so... "You need Wi-Fi (Airport) enabled on your Mac for the simulator to report a position with Xcode 3.2.3" but... "the simulator doesn't even use the WiFi, it always reports a fixed location in Cupertino anyway. ". Wooow. Is it a bug or what? Thank you anyway, I'll try this other solution you mention. – albertamg Jun 26 '10 at 15:08
  • Let me know if that works for you too. It's kind of hard to believe but I turned it on off 3 times and got the same results each time. – progrmr Jun 26 '10 at 21:34
  • This worked for me. I had the exact same problem over the last few days. Frustrating...I am on a iMac and turned on the AirPort...walla it location was updating properly again. – Steven Dorfmeister Jun 30 '10 at 01:21
  • I am also having the same issue on my MacBook, I tried to turn On / Off Airport. Even restarted didn't seem to fix the issue. :( Has anybody found a solution ? – Tharindu Madushanka Jul 10 '10 at 15:45
  • I ended up writing my own [CLLocationManager simulator class](http://github.com/progrmr/CLLocationManager-simulator) so I could do more testing on the iPhone simulator. You can use that if you can't get the iPhone simulator to give you any location. – progrmr Jul 10 '10 at 21:30
  • I think it could be the problem with 4.x CL framework, which has its default location(infinite loop, CA) replaced by error code. – Ameya Oct 03 '10 at 06:31
5

It did the same to me:

It showed the location at first, then I installed the XCode 4.2 beta, then when I went back to 4.1 location was not showing anymore and CLLocationManager was throwing a location error.

I did the following, and the problem was fix (I don't know if both actions are required or only one will suffice, because now it works and can't reproduce):

Run the simulator then:

  • unplug the network cable
  • change the device in simulator to iPhone (retina): Hardware > Device > iPhone (Retina)

I did this by mistake, and it fixed the location on my iMac.

Nicu Surdu
  • 8,172
  • 9
  • 68
  • 108
3

CLLocationManager started to work as expected again on the iOS Simulator 5.0.

In my experience, it used to fail consistently with kCLErrorDomain Code=0 on the iOS Simulator 4.0 through 4.3. Turning the airport on and connecting to a Wi-Fi, as suggested by the other answers, did not help in my case. However, I would like to thank everybody for their answers. I simply worked around this issue by testing all the Core Location code on a device.

Recently I upgraded to XCode 4.2 (from XCode 3.2.6) and the iOS Simulator 5.0 that comes with it, and as a result of that, I noticed that the CLLocationManager started to work as expected again. When selecting an older simulator in XCode 4.2, it keeps failing; which points to the simulator as the one to blame.

sKhan
  • 9,694
  • 16
  • 55
  • 53
albertamg
  • 28,492
  • 6
  • 64
  • 71
  • 3
    The simulator that comes with XCode 4.2 is much more capable. When running iOS Simulator, select the "Debug" menu, then select "Location" and you see a number of options for location simulation including Bike Ride, Freeway Drive, Custom Location, ... – progrmr Oct 21 '11 at 02:14
2

In Xcode 7 Simulator:

Hardware > Reboot

(Softer than "Reset Content and Settings")

sKhan
  • 9,694
  • 16
  • 55
  • 53
bauerMusic
  • 5,470
  • 5
  • 38
  • 53
2

Airport needs to be turned ON & you must join a network. At least that was my experience. When I just turned it on, I kept getting the same error. Joined my wireless network and the error went away.

sKhan
  • 9,694
  • 16
  • 55
  • 53
iNewbie
  • 21
  • 1
  • Thanks for your reply but when I get the error my Airport is ON and I'm connected to a network (I've tried 3 different networks actually). – albertamg Dec 29 '10 at 09:03
2

I kept getting an error until I switched my Airport on and connected to a wifi network (not sure if I am even supposed to be on that one!)... and CLLocationManager worked after failing consistently for ages. Is this a huge Simulator bug or what??!

Apple - PLEASE fix it! :P

sKhan
  • 9,694
  • 16
  • 55
  • 53
1

I'm normally Ethernet connected doing Simulator testing - I got this failure. Turned on WIFI, but not using it for data (didn't connect to anything) - now everything works.

So, the solution was - just turn on WIFI (I also quit and restarted the Simulator, not sure if needed to).

Lion and Xcode 4.2

sKhan
  • 9,694
  • 16
  • 55
  • 53
David H
  • 40,852
  • 12
  • 92
  • 138
1

This still occurs in iOS 5.0.1 under the following conditions:

  1. Run simulator in a situation without a wi-fi connection
  2. Connect to a wi-fi network
  3. [Result] CLLocationManager fails with error in outlined in this question.
  4. [Fix] Restart Simulator
sKhan
  • 9,694
  • 16
  • 55
  • 53
Undistraction
  • 42,754
  • 56
  • 195
  • 331
0

First Go to Xcode log bar and set "Dont simulate location". Then select simulator menu>debug>location>set custom or select any.

saraman
  • 568
  • 7
  • 19