-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotionManager.swift
More file actions
38 lines (29 loc) · 878 Bytes
/
Copy pathMotionManager.swift
File metadata and controls
38 lines (29 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// MotionManager.swift
// FilterTheWorld
//
// Created by Alexander Katzfey on 4/3/22.
//
import Foundation
import SwiftUI
import CoreMotion
class MotionManager: ObservableObject {
@Published var zAxis: Double = 0.0
private let magnitude = 10.0
private var manager: CMMotionManager
static let shared = MotionManager()
private init() {
self.manager = CMMotionManager()
self.manager.deviceMotionUpdateInterval = 1/60
self.manager.startDeviceMotionUpdates(to: .main) { (motionData, error) in
guard error == nil else {
print(error!)
return
}
if let motionData = motionData {
self.zAxis = motionData.userAcceleration.z * self.magnitude
//print(self.zAxis)
}
}
}
}