Once you've initialised the extension calling the
register function will start
the update of event updates (
Listening for the
CompassEvent.HEADING_UPDATED will give you periodic events with
When your application no longer requires the heading updates it's important to call
unregister to stop the active usage of the sensors on the device. This will
conserve battery life etc. This is important when your application goes into
background operation. It's suggested that you use a mechanism to unregister
the ANE when this occurs, by using something like the ACTIVATE/DEACTIVATE events.
On iOS you can access the true heading of the device, however this requires access to the device location so you will need to add some additional properties to your application and request permission to access the device location.
You will need to add the following to your iPhone info additions:
When you are going to be accessing the user's location you must check that your application has been allowed access. To this end the extension provides several helpers to check and request access to the location services.
On iOS the user must be asked at runtime, which you only get one chance to ask, after which you must direct the user to manually change the permissions in the settings.
You can check if you currently have permission using the
If this returns false you should expect a
-1 value for true heading.
To request authorisation at runtime, you call the
The following code will work across both platforms:
True Heading is not supported on Android