Last active
October 26, 2022 05:05
-
-
Save tetek/b01ac58710f945dd015f9006c8064420 to your computer and use it in GitHub Desktop.
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
| // Authorize the usage | |
| CMHeadphoneMotionManager.authorizationStatus() | |
| //Initialize the manager and set the delegate | |
| let motionManager = CMHeadphoneMotionManager() | |
| motionManager.delegate = self | |
| //Start tracking (simplified) | |
| //Implement the device motion handler callback to receive motion data | |
| if !motionManager.isDeviceMotionActive { | |
| motionManager.startDeviceMotionUpdates(to | |
| queue: OperationQueue, | |
| withHandler | |
| handler: @escaping CMHeadphoneMotionManager.DeviceMotionHandler) | |
| } | |
| //Don't forget to implement the delegates to cover connecting/disconnecting headphones | |
| func headphoneMotionManagerDidConnect(_ manager: CMHeadphoneMotionManager) {} | |
| func headphoneMotionManagerDidDisconnect(_ manager: CMHeadphoneMotionManager) {} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment