[F] Use linear acceleration rather than x-axis acceleration for shaking
This commit is contained in:
@@ -89,7 +89,7 @@ class AlarmActivationViewController: UIViewController
|
|||||||
{
|
{
|
||||||
// Check if the device has accelerometer
|
// Check if the device has accelerometer
|
||||||
var wvm = currentAlarm.wakeMethod.name
|
var wvm = currentAlarm.wakeMethod.name
|
||||||
if wvm == "Shake" && !motion.isAccelerometerAvailable
|
if wvm == "Shake" && !motion.isDeviceMotionAvailable
|
||||||
{
|
{
|
||||||
msg("Error", "Accelerometer is not available on your device, so shaking your phone wouldn't work.")
|
msg("Error", "Accelerometer is not available on your device, so shaking your phone wouldn't work.")
|
||||||
wvm = "Factor"
|
wvm = "Factor"
|
||||||
@@ -107,12 +107,14 @@ class AlarmActivationViewController: UIViewController
|
|||||||
shakeView.show()
|
shakeView.show()
|
||||||
|
|
||||||
// Start motion detection
|
// Start motion detection
|
||||||
motion.accelerometerUpdateInterval = 0.2
|
let q = OperationQueue()
|
||||||
motion.startAccelerometerUpdates(to: OperationQueue.current!) { data, error in
|
motion.deviceMotionUpdateInterval = 0.2
|
||||||
if data!.acceleration.x > 5
|
motion.startDeviceMotionUpdates(to: q) { data, error in
|
||||||
|
if let a = data?.userAcceleration, sqrt(pow(a.x, 2) + pow(a.y, 2) + pow(a.z, 2)) > 4
|
||||||
{
|
{
|
||||||
ui { self.endAlarm() }
|
ui { self.endAlarm() }
|
||||||
motion.stopAccelerometerUpdates()
|
motion.stopDeviceMotionUpdates()
|
||||||
|
q.cancelAllOperations()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user