Note that the following is a work-around. I urge everybody to file a bug-report with Apple, to make sure there is pressure on Apple to fix this.
Others have suggested the CMSensorRecorder work-around. It turns out that the "Fitness Tracking" setting in the Settings App needs to be enabled for that to work.
When the authorizationStatus is .restricted, then the user first needs to switch on Settings > "Privacy & Security" > "Motion & Fitness" > "Fitness Tracking"
When the authorizationStatus is .notDetermined, then start the CMSensorRecorder. A "Motion & Fitness" privacy settings will be added to your app's settings, and the user will be asked to authorise by iOS. When the user accepts, authorizationStatus changes to .authorized and you can start the CMAltimeter.
When the authorizationStatus is .denied, the user needs to switch on the "Motion & Fitness" privacy setting of your app.
The following code worked for me:
let status = CMAltimeter.authorizationStatus()
switch status {
case .notDetermined:
// trigger a authorization popup
let recorder = CMSensorRecorder()
DispatchQueue.global().async {
recorder.recordAccelerometer(forDuration: 0.1)
}
case .restricted:
popupText = "Please switch \"Fitness Tracking\" on, in the Apple Settings app, under \"Privacy & Security\" > \"Motion & Fitness\""
showingPopup = true
case .denied:
popupText = "Please switch \"Motion & Fitness\" on, in the app settings"
showingPopup = true
default:
print("authorized")
}
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
let status = CMAltimeter.authorizationStatus()
if status == .authorized {
timer.invalidate()
self.altimeter.startRelativeAltitudeUpdates(to: OperationQueue.main) { (data, _error) in
// handle altimeter data
}
}
}