来自陀螺仪的数据无法在Apple Watch上运行

时间:2018-05-16 03:34:44

标签: ios swift gyroscope

带有加速度计的代码在Apple Watch上运行良好

if motionManager.isDeviceMotionAvailable {
            motionManager.deviceMotionUpdateInterval = 0.2
            motionManager.startDeviceMotionUpdates(to: OperationQueue.current!) { (data, error) in
                if data!.userAcceleration.z < -0.5 {
                    self.myOutlet.setBackgroundColor(UIColor.red)
                    self.myLabel.setText("Green")
                } else if data!.userAcceleration.z > 0.5 {
                    self.myOutlet.setBackgroundColor(UIColor.green)
                    self.myLabel.setText("Red")
                }

但如果我正在尝试使用陀螺仪

if motionManager.isGyroAvailable {
            motionManager.gyroUpdateInterval = 0.2
            motionManager.startGyroUpdates(to: OperationQueue.current!) { (data, error) in
                if data!.rotationRate.y > 0.1 {
                    self.counter.addOne()
                    self.myLabel.setText("\(self.counter.toString())")
                }
            }
        }

他们没有任何反应:( Apple Watch不支持访问陀螺仪或我做错了什么?

0 个答案:

没有答案