Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect compass calibration switch state on iOS

I am currently working with the CLLocationManager and want to get informed about the current heading of the device. So far everything works fine, features are implemented and now i try to polish my app.

There is a corner case, if the user will turn off the compass calibration flag in the user settings heading updates will not be send any more to my app. In such a case I want to give the user some feedback, that he has to turn on compass calibration again otherwise my app will not work.

I figured out that in case of the user turns off the location services for my app I will still receive magnetic heading. But if the "compass calibration" setting will be turned of by the user I will not receive any longer heading updates. But how can i identify through the CoreLocation framework that "compass calibration" was turned off?

The "CLLocationManagerDelegate" gives me an update through the

- (void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 

method. But the status indicates only if the "location services" is in-/active for my app.

I also tried to get some valid informations through the

- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error

delegate method, without any success.

Is there something in the CoreLocation framework that can tell me if "compass calibration" flag is turned on/off.

like image 260
Alathink Avatar asked Dec 05 '12 15:12

Alathink


People also ask

Why is my Compass wrong on my iPhone?

Your Compass app may show the wrong direction because of magnetic interference. Compass is very sensitive to interference. Magnetic interference can be caused by electronic objects. You may be experiencing interference from a nearby power line, a microwave oven, or another electrical device.

How accurate is Compass on iPhone?

However, some critics have noted that the Compass app isn't always accurate. According to Apple, even the slightest magnetic interference (even from devices like your AirPods) can "cause a deviation."

Can I turn off Compass calibration iPhone?

Steps to enable/disable Compass Calibration in iPhone/iPad:Step 1: Access System Services. Open Settings, choose Privacy, click Location Services and tap System Services. Step 2: Enable or disable Compass Calibration.


1 Answers

From what I've found, newHeading.trueHeading in locationManager:didUpdateHeading: should be -1 if compass calibration is turned off. This should do it:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    if(newHeading.trueHeading == -1)
        //Compass calibration is off provided location services are on for the app
}
like image 190
Rick Avatar answered Oct 15 '22 19:10

Rick