0

Inspired by Nike Running application, I would want to know how can I get gyroscope updates in the Xcode console when the app is in Background/Minimized state. Below mentioned code is working just fine and showing reading of axes pretty smoothly.

    override func viewDidLoad() {
    super.viewDidLoad()

    let motionManager = CMMotionManager()

        motionManager.gyroUpdateInterval = 0.1
        motionManager.startGyroUpdates()
        if motionManager.deviceMotionAvailable {
            motionManager.deviceMotionUpdateInterval = 0.01

            motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { (data: CMDeviceMotion?, error: NSError?) -> Void in
                let x = data!.gravity.x
                let y = data!.gravity.y
                let z = data!.gravity.z

                print(x)

                self.view.backgroundColor = UIColor(
                    red: CGFloat(abs(x)),
                    green: CGFloat(abs(y)),
                    blue: CGFloat(abs(z)),
                    alpha: 1.0)
            })
        }
    }
jscs
  • 63,694
  • 13
  • 151
  • 195
Codetard
  • 2,441
  • 28
  • 34
  • What is your question? You mention the code is working and giving the readings you want. – fsb May 07 '16 at 14:39
  • @fbara I would want to know how can I get gyroscope updates in the Xcode console when the app is in Background/Minimized state. – Codetard May 07 '16 at 17:04
  • Maybe [this answer](http://stackoverflow.com/a/22548623/2557145) helps. It provides a trick to allow for continuous background updates by activating background audio playback. – Palle May 07 '16 at 18:07
  • Is there any similar workaround HeatlhKit API has? – Codetard May 07 '16 at 18:57
  • I don't really find this idea robust actually, thanks everyone. I will try HeathKit and post result. – Codetard May 07 '16 at 18:59

0 Answers0