You can now by using "magneticHeading" or "trueHeading" from Core Location (Apple Watch Serie 5+, watchOS 6.0+)
Here is a basic example:
import CoreLocation
class yourClass {
let locationManager = CLLocationManager()
init() {
setupCoreLocation()
}
func setupCoreLocation() {
guard CLLocationManager.headingAvailable() else { return }
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
// additional setup available if needed
}
}
extension yourClass: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
let magneticHeading = newHeading.magneticHeading
let trueHeading = newHeading.trueHeading
// Do something with the new heading values
}
}
Then when you need the heading values you do:
locationManager.startUpdatingHeading()
And when you don't need them anymore you do:
locationManager.stopUpdatingHeading()
Here are all the official Apple documentations:
Core Location
CLHeading
magneticHeading
trueHeading
Heading and Course Information basic knowledge
Don't forget to check if "heading" is available first: headingAvailable()