From 1e2248d97eda3e8a4c0369173b081dd6d00ce007 Mon Sep 17 00:00:00 2001 From: Zabadam <65806473+Zabadam@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:08:59 -0500 Subject: [PATCH] Obtain magnetometer events from DeviceMotion rather than raw startMagnetometerUpdates(). This also makes the magnetometer onCancel() method now correct. Added set 'showsDeviceMovementDisplay' to true for magnetometer. --- .../sensors_plus/ios/Classes/FPPStreamHandlerPlus.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/sensors_plus/sensors_plus/ios/Classes/FPPStreamHandlerPlus.swift b/packages/sensors_plus/sensors_plus/ios/Classes/FPPStreamHandlerPlus.swift index fa64accc40f..4fa23625241 100644 --- a/packages/sensors_plus/sensors_plus/ios/Classes/FPPStreamHandlerPlus.swift +++ b/packages/sensors_plus/sensors_plus/ios/Classes/FPPStreamHandlerPlus.swift @@ -192,7 +192,10 @@ class FPPMagnetometerStreamHandlerPlus: NSObject, MotionStreamHandler { eventSink sink: @escaping FlutterEventSink ) -> FlutterError? { _initMotionManager() - _motionManager.startMagnetometerUpdates(to: OperationQueue()) { data, error in + _motionManager.showsDeviceMovementDisplay = true + _motionManager.startDeviceMotionUpdates( + using: CMAttitudeReferenceFrame.xArbitraryCorrectedZVertical, to: OperationQueue() + ) { data, error in if _isCleanUp { return } @@ -204,7 +207,7 @@ class FPPMagnetometerStreamHandlerPlus: NSObject, MotionStreamHandler { )) return } - let magneticField = data!.magneticField + let magneticField = data!.magneticField.field sendTriplet(x: magneticField.x, y: magneticField.y, z: magneticField.z, sink: sink) } return nil