'When video record if device move too fast show warning?

I would like to show a warning on speed when the user moves the device too fast while recording a video.

We also used ARKit for some different purpose

I used CoreMotion but still, it will not give me proper data when the device moves too fast.

I also try this SO answer but it will increase speed every time.

func enableAccSensor() {
        
        if motionManager == nil {
            motionManager = CMMotionManager()
            motionManager?.gyroUpdateInterval = 1.0 / imuFreq
            motionManager?.accelerometerUpdateInterval = 1.0 / imuFreq
            motionManager?.deviceMotionUpdateInterval = 1.0 // imuFreq
        }
        if accelgyroQueue == nil {
            accelgyroQueue = OperationQueue.init()
            accelgyroQueue?.qualityOfService = .background
        }
        guard let accelgyroQueue = accelgyroQueue else { return }
        if motionManager?.isAccelerometerAvailable ?? false {
            motionManager?.startAccelerometerUpdates(to: accelgyroQueue, withHandler: { [weak self] (accelerometerData, error) in
                self?.outputAccelertionData(acceldata: accelerometerData)
                if let error = error {
                    DispatchQueue.main.async(execute: {
                        ShowToast.show(toatMessage: Messages().kAccelerometerError, isDelayNeeded: true)
                    })
                    print("motionManager:",error)
                    
                }
            })
        }
        
    }
  
    func outputAccelertionData(acceldata: CMAccelerometerData?) {

        if let acceldata = acceldata {
            print("outputAccelertionData:",acceldata)
            if self.processState == .scanning || self.processState == .none {
                
                if acceldata.acceleration.x >= 0.80 {
                    lastOrientation = .landscapeLeft
                }
                else if acceldata.acceleration.x <= -0.80 {
                    lastOrientation = .landscapeRight
                }
                else if acceldata.acceleration.y <= -0.80 {
                    lastOrientation = .portrait
                }
                else if acceldata.acceleration.y >= 0.80 {
                    lastOrientation = .portraitUpsideDown
                }
                
                DispatchQueue.main.async(execute: { [weak self] in
                            self.setDataCallback(operations: .deviceOrientation(rotateAt: self.lastOrientation))

                })
                
            } 
        }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source