headingBody
A physical body or view that defines the reference orientation for heading calculations.
Declaration
var headingBody: (any CLBodyIdentifiable)? { get set }Discussion
Set this property to associate heading calculations with a specific body or view, such as a UIKit UIView that conforms to CLBodyIdentifiable.
When this property is nil, the location manager uses the physical orientation specified by headingOrientation. When you assign a view conforming to CLBodyIdentifiable to this property, Core Location calculates heading relative to the top of that view and ignores headingOrientation. The system updates this calculation automatically whenever the view rotates or changes position.
On iPhone Duo, setting this property also identifies which display your app occupies. For example, when iPhone Duo rests camera-side down on a surface, setting headingBody to your view allows your app to receive heading data relative to that active display and detect which face is up.
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Align heading updates with this view's orientation.
locationManager.headingBody = view
locationManager.delegate = self
locationManager.startUpdatingHeading()
}