How to get motion updates from CMMotionManager in the background ios 13 swift

284 Views Asked by At

I am trying to get background motion updates but as soon as the application goes in background, the motion stops updating. I tried using background mode with audio enabled but got nothing. Any help would be appreciated.

    motionManager.startDeviceMotionUpdates(to: OperationQueue.current!) {
        (data, error) in
        if let trueData = data {
            print("\(trueData)")
        }
    }

motionManager is of type CMMotionManager.

I also tried this in onDisappear()

 let session = AVAudioSession.sharedInstance()
   do{
      var player: AVPlayer = AVPlayer()
      try session.setCategory(AVAudioSession.Category.playback)
      try session.setActive(true)
      self.stopMotionSensors()
      self.startMotionSensors()
      player.play()

   } catch {}
0

There are 0 best solutions below