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)
})
}
}