CLLocationManager on iPhone Simulator fails with kCLErrorDomain Code=0
Asked Answered
S

13

42

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.

Stereoscopic answered 24/6, 2010 at 14:8 Comment(4)
Im having exactly the same problem since upgrading to sdk 4Unionize
Have you opened your project by any chance with XCode 4.2 beta ?Gimbals
@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.Stereoscopic
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.Sewell
S
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.

Stereoscopic answered 20/10, 2011 at 18:25 Comment(1)
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, ...Danielledaniels
B
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.

Brigade answered 18/6, 2013 at 8:40 Comment(2)
this did it for me. it was set to None in my project.Bowel
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.Aerial
M
19

Following Steps fixed my problem:

  1. Under the Simulator menu: Reset Content and Settings....
  2. Close the simulator
  3. Restart your app.
Maidenhair answered 2/12, 2011 at 8:21 Comment(1)
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.Unapproachable
C
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..

Chrissychrist answered 23/10, 2012 at 9:1 Comment(0)
D
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.

Danielledaniels answered 25/6, 2010 at 20:2 Comment(8)
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 #2140840)Stereoscopic
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 for use on the simulator.Danielledaniels
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.Stereoscopic
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.Danielledaniels
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.Has
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 ?Jeana
I ended up writing my own CLLocationManager simulator class 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.Danielledaniels
I think it could be the problem with 4.x CL framework, which has its default location(infinite loop, CA) replaced by error code.Amphibolite
T
7

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

Terrorstricken answered 3/5, 2013 at 12:40 Comment(1)
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.Milline
G
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.

Gimbals answered 19/10, 2011 at 10:11 Comment(1)
+1 Thanks for the input. I explained my experience in an answer below.Stereoscopic
S
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.

Stereoscopic answered 20/10, 2011 at 18:25 Comment(1)
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, ...Danielledaniels
P
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.

Pacorro answered 28/12, 2010 at 13:4 Comment(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).Stereoscopic
A
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

Assibilate answered 10/2, 2011 at 16:47 Comment(0)
T
2

In Xcode 7 Simulator:

Hardware > Reboot

(Softer than "Reset Content and Settings")

Tainataint answered 18/11, 2015 at 15:16 Comment(1)
Doesn't work for me. The error still appears occasionally.Lated
C
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

Commentate answered 16/11, 2011 at 19:31 Comment(0)
C
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
Costive answered 29/11, 2011 at 10:40 Comment(0)
R
0

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

Rebutter answered 4/7, 2016 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.