I have apps using CMAltimeter to get sensor data, but recently they stop working with iOS 17.4, it is not release but some user running beta version, the is no access to the sensor data anymore (altitude and barometer). Some user report they can fix it by manual the "Motion & Fitness" permission but it only appear on some device. Report has been sent to Apple but I post here to find the solution to fix it.
Hello all, as you may have realized by now, 17.4.1 has not fixed the problem you have been seeing.
I would like to first clarify what problem we are talking about, and for what problem we are recommending a workaround and waiting for a fix. The "problem" is twofold:
- Starting with iOS 17.4 using CMAltimeter requires the declaration of
NSMotionUsageDescription
, authorization by the user, and have not turned off Fitness Tracking in settings:
This is not a bug. This is a permanent change per privacy requirements, and it is not going to go back to a state as before iOS 17.4, so you must change your app to include this privacy change.
- Along with the above change, there was a behavior mismatch where if the app is only using CMAltimeter APIs like
startRelativeAltitudeUpdates()
in a simple pattern, this was not triggering the authorization prompt necessary for the altimeter data to be accessed. Apps that were already using other APIs that required this permission earlier, do not run into this issue.
This behavior is the one we are looking to change, where simply using CMAltimeter
in a simple pattern will be enough to obtain the authorization. This change was not made in 17.4.1 but is being investigated for a future version.
To alleviate this, I had suggested a workaround using the CMPedometer
API that was going to trigger the authorization prompt, after which apps only using CMAltimeter
would work without issues. While that workaround we came up with quickly still works, we now have a better recommendation that does not require the use of another API, and we believe is more power efficient and has wider support of devices. The new recommended workaround is this:
func startAltitudeUpdatesViaMotionManager() {
self.motionActivityMotionManager.queryActivityStarting(from: .now, to: .now, to: .main) { _, _
in
self.altimeterManager.startRelativeAltitudeUpdates(to: .main) { altitudeData, error
// Handle altitude updates
}
}
}
If you call startRelativeAltitudeUpdates()
using this pattern, this will solve the issue of the authorization prompt not appearing when using a more simple pattern. Also, this does not require the use of an unrelated and API which you would want to rush to remove from your code once a change is made to have the simple call patterns to trigger the authorization dialog.