In Interfacecontroller.swift
I have a class variable var motionManager = CMMotionManager()
and var accTest = [Double]()
which I refer to in this piece of code:
let useOnlyAccelerometer = true
if useOnlyAccelerometer {
motionManager.accelerometerUpdateInterval = 0.1
if motionManager.accelerometerAvailable {
let handler:CMAccelerometerHandler = {(data: CMAccelerometerData?, error: NSError?) -> Void in
self.statusLabel.setText(String(format: "%.2f", data!.acceleration.x))
self.accTest.append(data!.acceleration.x)
}
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: handler)
}
} else {
motionManager.deviceMotionUpdateInterval = 0.1
if motionManager.deviceMotionAvailable {
let handler:CMDeviceMotionHandler = {(motion: CMDeviceMotion?, error: NSError?) -> Void in
self.statusLabel.setText(String(format: "%.2f", motion!.userAcceleration.x))
self.accTest.append(motion!.userAcceleration.x)
}
motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: handler)
}
}
Using directly the accelerometer works. Now, if I change useOnlyAccelerometer
to false
then it does not work. I do not understand the difference or what is going wrong. On the iPhone it does work, and according to the documentation watchOS2 should support CMDeviceMotion
. Any ideas?
My conjecture is that the magnetometer is not supported on 1st generation Apple Watch. Ifixit revealed that there is magnet on the watch to connect it to its charger. In the labs at WWDC 2016, I asked an Apple Engineer if the magnetometer would ever be supported and got a rather delphic reply: "that would require a powerful magnetometer, wouldn't it?" I have no idea if the means that there will be support in the future or not.
So, if magnetometer is NOT supported, then CMDeviceMotion's return value for
public var magneticField: CMCalibratedMagneticField { get }
would be undefined. Would suggest filing a bug report.