Skip to content

Instantly share code, notes, and snippets.

@cafielo
Created January 30, 2021 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cafielo/815fd66542d9639869edb396e0f18197 to your computer and use it in GitHub Desktop.
Save cafielo/815fd66542d9639869edb396e0f18197 to your computer and use it in GitHub Desktop.
import coremotion
// 1 import
import CoreMotion
// 2 create property that can store CMMotionManager
var motionManager: CMMotionManager!
// 3 initialize it
motionManager = CMMotionManager()
// 4 check accelermoter is available
if motionManager.isAccelerometerAvailable {
// 5 set update interval
motionManager.accelerometerUpdateInterval = 0.1
// 6 write your logic in the closure
motionManager.startAccelerometerUpdates(to: OperationQueue.main) { (data, error) in
print(data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment