3 、userAcceleration:加速速信息。
4 、rotationRate:計(jì)時(shí)的旋轉(zhuǎn)速率,是陀螺儀的輸出。
CoreMotion中有兩種獲取數(shù)據(jù)的方式:
1、Push
方式:提供一個(gè)線程管理器NSOperationQueue和一個(gè)回調(diào)Block,CoreMotion自動(dòng)在每一個(gè)采樣數(shù)據(jù)到來的時(shí)候回調(diào)這個(gè)Block,進(jìn)行處理。在這種情況下,Block中的操作會(huì)在你自己的 主線程 內(nèi)執(zhí)行。
2、Pull
方式:你必須主動(dòng)去向CMMotionManager要數(shù)據(jù),這個(gè)數(shù)據(jù)就是最近一次的采數(shù)據(jù)。你不去要,CMMotionManager就不會(huì)給你。
push方式獲取加速計(jì)數(shù)據(jù)

Push.png
push方式獲取陀螺儀數(shù)據(jù)

gyro-Push.png
push方式獲取計(jì)步器數(shù)據(jù)
下面是iOS7的用法

cmStepCounter.png
iOS8之后取代CMStepCounter的是 CMPedometer ,代碼如下
首先聲明一個(gè)屬性
[email protected] (nonatomic, strong) CMPedometer *pedometer;
接下來就可以初始化,通過下面的代碼就可以了,注意紅框框選住的是獲取某一段時(shí)間所走步數(shù)的代碼

iOS8計(jì)步.png