IOS 摇一摇和计步器
2020-05-28 本文已影响0人
越天高
摇一摇
override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
print("用户开始摇一摇")
}
override func motionCancelled(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
print("被打断")
}
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?)
{
print("摇一摇结束")
}
计步器
//ios8.0之后使用
//判断记步是否可用
if !CMPedometer.isStepCountingAvailable()
{
print("计步器不可用")
return
}
cmPedmeter.startUpdates(from: Date(timeIntervalSinceNow: 0) )
{ (pedData, error) in
if error != nil
{
return
}
// CMPedometerData
// numberOfSteps: 走了多少部
// distance: 走了多远
// floorsAscended: 上楼层数
// floorsDescended: 下楼层数
print(pedData?.numberOfSteps, pedData?.distance)
}