Location Manager Error : (KCLErrorDomain error 0) - iphone

Location Manager Error : Operation could not be completed(KCLErrorDomain error 0)
Why does this error occur?

This error occurs if you have Scheme/Edit Scheme/Options/Allow Location Simulation checked but don't have a default location set. I'm sure there are other causes as well though.

UPDATE
THANKS TO Ben Marten
You can make it permanent using these steps in XCode:
Product > Scheme > Edit Scheme
Click Run .app
Option tab
Already checked Core Location > select your location
Press OK
Besides that, even if you are not connected to wifi, you can set a location in simulator through top menu items Debug>Location and to make it permanent follow steps above

I just had this problem. Took me a while to find the solution, which is only loosely related to the previous poster's answer.
Airport (WiFi) must be on for CoreLocation in the iPhone/iPad Simulator to work. I was connected via Ethernet so CL didn't do anything in the Simulator. Turn on Airport in your Network Settings and try again. You can change the order of your network interfaces by dragging Airport below Ethernet if you want to continue favoring your wired connection over your wireless...

From the API docs:
CLError
Error codes returned by the location
manager object.
typedef enum { kCLErrorLocationUnknown
= 0, kCLErrorDenied, kCLErrorNetwork, kCLErrorHeadingFailure } CLError;
Constants
kCLErrorLocationUnknown The location
manager was unable to obtain a
location value right now.Available in
iPhone OS 2.0 and later. Declared in
CLError.h.
kCLErrorDenied Access to the location
service was denied by the user.
Available in iPhone OS 2.0 and later.
Declared in CLError.h.
kCLErrorNetwork The network was
unavailable or a network error
occurred. Available in iPhone OS 3.0b
and later. Declared in CLError.h.
kCLErrorHeadingFailure The heading
could not be determined. Available in
iPhone OS 3.0 and later. Declared in
CLError.h.
So this means the location could not be determined.
I would guess the most likely cause is that the location manager is using WiFi to triangulate the location, and the database doesn't cover the local networks. That apparently can be fixed by the user if they go here.
However as I noted I have also seen this occasionally as a transient error when running a location based program in a location where the WiFi location stuff normally works.
Lastly I guess it is possible to see this error if there is some kind of hardware failure.

1) check that you actually have a valid WiFi and 3G connection
if you do then
2) go to settings and reset your location services
3) reset your network settings

If you got this in Emulator then do following
Debug > Location > ✓ Apple

This error is thrown when Location Manager is unable to get location information immediately. I found that this error was occurring when startUpdatingLocation method was called. For me, this was happening on iPod but not on iPhone. That makes sense, since, iPhone has more ways (like cellular network) to get location information and is able get a quick estimate on the location whereas iPod takes more time which caused this error to be raised on iPod.
Since, when this error is thrown locationManager:didFailWithError: delegate method is called, one can handle this specific case in a conditional statement by matching "[error domain]" and "[error code]" from the error object passed to this method.

The exact reason what I have found is there is a conflict occuring in the location simulation in both the ios simulator “Debug settings” and in the xcode settings “Edit schemes”.Ensure to set you default user location in any one of this and mark the other to None solved the problem hope this might help for sure.
InXcode:
In iphone/ipad simulator:

You can add your own list of locations to Xcode to test your applications with.
From within Xcode select the menu Debug/Simulate Location and you'll be offered:
a. "Don't Simulate Location"
b. 12 example locations
c. "Add GPX File to Project..."
Select "Add GPX File to Project..." and select the GPX file you've created.

Go to Xcode project >product>scheme>edit scheme>chek location simulation>set your location> and run app again Hope it will works !

Thanks to this article (https://possiblemobile.com/2013/04/using-xcode-to-test-location-services/) I got a hint to look at the data on my custom GPX file and there found the issue.
Some GPX files you might get from different sources might have the following elements indicating the different coordinates in specified path. This wont work with Xcode's Location Simulation.
<gpx>
...
<trkpt lat="" lon="">
<ele></ele>
</trkpt>
...
</gpx>
What you should do is find all occurrences of the "trkpt" element and replace it with "wpt" in your favorite text/xml editor. The end result should be something as follows:
<gpx>
<wpt lat="" lon="">
<ele></ele>
</wpt>
...
</gpx>
Hope this helps! It certainly helped me.

This error occur while you run your program ,but you simulate location after you run the programe.
I get a method :quit your simulator and restart it ,then set your simulator location before you run the programe,and it works for me .
Hope this helps! It certainly helped me.
thanks...

all of this didn't work for me.. what worked for me is :-
set the location from the simulator to none then change it back to custom location while the app is running.

All of the suggestions didn't help in my case. What helped was to uninstall the app from the simulator device, reinstall it and allow it to access the location (in the settings app).

If you are getting this on the device, chances are you did not ask for or the user denied the permission to gather the location.

Related

Simulating a location on Real iOS Device

Is it possible to simulate a location on iOS Device, say I want to simulate London on the device while I am sitting in Oxford?
Thanks.
Yes, It is possible to simulate the location on device in debug mode. All you need is to debug your application on device, and then enable the location from debug menu.
Check this link...
https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/simulating_locations.html
You can create a GPX file with the desired location/coordinates and you can enable it from the debugger or from the Project scheme select run/options/"Allow location simulation".
After you have this enabled and your device connected the location simulation will work on the device to till you reboot it.
A good article that explain this can be found here: https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
Maybe this project can help: https://github.com/futuretap/FTLocationSimulator
It simulate location sending fake data to the coreLocation.

What does Core Motion error 102 mean?

I use Core Motion's sensor fusing to get north oriented motion updates:
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:motionQueue withHandler:motionHandler]
In a very rare case that can be reproduced only on selected customer devices (iPhone 4S running iOS 6.0.2) I receive this error in the motionHandler:
Error Domain=CMErrorDomain Code=102 "The operation couldn’t be completed. (CMErrorDomain error 102.)
Also, it seems I don't get any valid deviceMotion updates after that. Does anybody know what this error 102 means? I can't find anything in the documentation.
As Krishnabhadra correctly pointed out, this error code means CMErrorTrueNorthNotAvailable. The description ("True north is not available on this device. This usually indicates that the device’s location is not yet available.") unfortunately doesn't give any hint how to solve the issue so I'd like to describe my findings when this error occurs.
It occurs on a tiny (a handful out of many thousands) fraction of iOS 6.0+ devices when using CMAttitudeReferenceFrameXTrueNorthZVertical (CMAttitudeReferenceFrameXMagneticNorthZVertical is OK). Despite the error description, Core Location works correctly. On affected devices the bug is triggered in 100% of the cases and blocks Core Motion updates completely. -[CMMotionManager deviceMotion] always returns nil.
Resetting the iOS system settings fixes the problem.
I’ve logged rdar://12952327 with some more details.
Update:
This error occurs if compass calibration is disabled in the privacy / location services / system services section.
From documentation
typedef enum {
CMErrorNULL = 100,
CMErrorDeviceRequiresMovement,
CMErrorTrueNorthNotAvailable
} CMError;
It seems error 102 is CMErrorTrueNorthNotAvailable, and its description is
CMErrorTrueNorthNotAvailable
It seems not much information is available regarding what causes this error. It can be any hardware issue with the device.
Also, make sure this is enabled. After I enabled this option, I did not encounter the 102 issue anymore while using xTrueNorthZVertical.
Settings > Privacy > Location Services > System Services > Compass Calibration
102 is CMErrorTrueNorthNotAvailable. I guess that your device has problems with determining north direction or something.
I got this error and when i tried to find solution, apparently my location services in my device are switched off, once i switched on, it worked.

show current user location?

I know this has been asked by many others. I just wanted to know that by now the simulator is still unable to detect the current location (it always detects it as Cupertino). Is this true? Has apple actually done some update on this issue?
No, and they won't. The simulator is a joke. It should only be used when fiddling around before you get approved for the iOS Dev program. All actual debugging should be done on a device. Period.
In the simulator you cant see the current location,if u write code for to display current location, in simulator it shows default sanfrancisco location.Run That application in device then it shows curtrent location

Disable location service in iPhone simulator?

I'd like to test what happens if my app can't get the location coordinates. Is it possible to disable the location service in the simulator, like on an iPod Touch with WiFI turned off?
I still don't have my iPhone Developer Program certificate, so I can't test it on my device.
Thanks in advance!
You can disable the location services in the simulator;
Run your app through xcode so the simulator opens
Stop the app via xcode (this should leave the simulator open)
Open the Settings app in the simulator window
Privacy > Location Services. Disable Location Services
Run your app again, location services should be disabled
Hope it helps!
As a workaround you can try to simulate update location failure by constructing NSError object with appropriate values and calling corresponding CLLocationManager delegate didFailWithError: method manually.
To my knowledge, you can't disable the location service on the simulator.
The approach that I normally use when using the location service is to build a simple wrapper class arround NSLocation tailored to the needs of my application.
In this wrapper, you could easily pretend that the service is not working in the simulator. For example, it could have a "isEnabled" method that returns false on the simulator with a compiler define like (#if TARGET_ IPHONE_SIMULATOR)
**Disregard this. This works around the MapKit. Check comments below.
Disconnect the computer from internet connection. How to.
EDIT: You can test the code from this site that can be downloaded here
With AirPort on, you get the map. With the AirPort off you get a blank squared view.

Core Location on simulator & device

When testing on simulator i wont get this pop up "Would you allowed this app to use your current location" ,but while testing on device this message pops up.Does anybody know why it is?
It is because in the Simulator, you are testing your app, and there is no real location data. It only appears on the device for privacy reasons which, of course, don't exist in the simulator.
You can select any location as your current location while testing your app on the simulator,by Selecting the Simulate Location option
There is something called iSimulate that lets you do this, but you have to pay for this.
You get this pop up on device because it is related with some privacy, this is some that the SDK does to verify if the user really wants to allow the app to get info about the device location.
On simulator, it doesn't happen only because Apple doesn't want, but I think it should be asked, so we could simulate some behavior when the user doesn't allow the use of the GPS.
Cheers,
VFN
You can add custom location with custom latitude/longitude using GPX file.
GPX is xml format file for adding custom location to location simulate service.
Here is great example : http://blackpixel.com/blog/2013/05/simulating-locations-with-xcode.html
According this example, you can create and add gpx file easily. GPX file is standardized file type to simulate locations.
GPX file format looks like
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="-00.000000" lon="00.00000">
<name>London</name>
</wpt>
</gpx>
After adding this file to xCode, just select Location to this file in Edit Scheme from top left of xCode.
Let me know if another help needed.