I’ve been playing around with CLLocationManager (the base class for Location updates).
I hooked up with its delegate to receive heading updates.
My app is correctly receiving CLHeading objects as pointers (Ptr).
The problem was reading the magneticHeading value.
The following declare always returns 0:
Declare function magneticHeading_ lib "CoreLocation" selector "magneticHeading" (obj as ptr) as Double
Return magneticHeading_(ptrHeading).value //Always returns 0.0
It took me a few hours to figure that the above declare should instead return a Structure that only contains one double value.
So I defined the following structure:
Structure CLHeadingStructure
value as Double
End Structure
And then got the value like this:
Declare function magneticHeading_ lib "CoreLocation" selector "magneticHeading" (obj as ptr) as CLHeadingStructure
Return magneticHeading_(ptrHeading).value //Returns the correct value
@Greg_O or @Sam_Rowlands would you be able to explain why a Structure is needed here?
It’s not a structure, it’s a type alias to double. So a double should just work here.
Declare function magneticHeading_ lib "CoreLocation" selector "magneticHeading" (obj as ptr) as Double
Return magneticHeading_(ptrHeading)
CLLocation_magneticHeading is a better name for the function IMHO as you include the class name in the call, which makes it easier for you and others to look up in the future.
That is also my conclusion.
It’s not uncommon for Apple’s documentation to be not quite right, have you checked the header files for the class? Sometimes these can fill in the missing parts from the web documentation and sometimes not.
I would also check with multiple versions of iOS; as again it’s not uncommon for API to return different results for different versions, and Apple’s docs make no mention of this.
As for running an a physical device, that’s something I canna help you with here as I quit iOS last year.