Skip to content

Instantly share code, notes, and snippets.

@NikhilManapure
Created July 22, 2017 05:38
Show Gist options
  • Select an option

  • Save NikhilManapure/973344182b501fd3ae3a29dac74ceeda to your computer and use it in GitHub Desktop.

Select an option

Save NikhilManapure/973344182b501fd3ae3a29dac74ceeda to your computer and use it in GitHub Desktop.
let motionManager = CMMotionManager() // Class variable, otherwise ARC will delete the object
if motionManager.isGyroAvailable {
if !motionManager.isGyroActive {
motionManager.gyroUpdateInterval = 1.0 / 2.0
motionManager.startGyroUpdates(to: .main, withHandler: { (gyroData, error) in
if let gyroData = gyroData {
print(String(format: "%.02f %.02f %.02f", gyroData.rotationRate.x, gyroData.rotationRate.y, gyroData.rotationRate.z))
} else if let error = error {
print("1Error \(error.localizedDescription)")
} else {
print("2Error")
}
})
} else {
print("isGyroActive = true")
}
} else {
print("isGyroAvailable = false")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment