Apple Watch和Swift在使用CoreMotion计算设备运动时崩溃



目前正在使用 Apple Watch 来计算其偏航角、俯仰角和横滚角。

但是,当尝试使用Core Motion功能时,应用程序崩溃。有没有人遇到过这个问题?

if motionManager.deviceMotionAvailable{
    self.referenceAttitude = self.deviceMotionManger.attitude
    let currentAttitude : CMAttitude = self.deviceMotionManger.attitude
    currentAttitude.multiplyByInverseOfAttitude(self.referenceAttitude)
    self.Yaw.setText( "Yaw " + String(format: "%.1f", currentAttitude.yaw))
    self.Pitch.setText( "Pitch " + String(format: "%.1f", currentAttitude.pitch))
    self.Roll.setText("Roll " + String(format: "%.1f", currentAttitude.roll) )
}
else {
    self.Yaw.setText("device motion is not" + String(motionManager.deviceMotionActive))
}

Apple Watch 提供的唯一核心运动数据是原始加速度计数据。

手表不会提供原始陀螺仪数据、原始磁力计数据或处理的设备运动数据; deviceMotionAvailable将始终返回 false。

至于崩溃,当隐式解包的Yaw标签的出口未连接到情节提要时,您会得到"致命错误:在解包可选值时意外发现 nil"。

最新更新