Created
January 30, 2021 18:15
-
-
Save cafielo/815fd66542d9639869edb396e0f18197 to your computer and use it in GitHub Desktop.
import coremotion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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