ios - 如何按步数获取CMPedometer数据?
<p>我目前在医疗保健应用程序中工作,该应用程序需要跟踪用户手持手机行走时的步数。我已经使用了<code>CoreMotion</code>框架和<code>CMPedometer</code>来跟踪步数,并且效果很好。但是,回调函数不会在每个步骤计数后都调用。它汇总所有数据,并以10个步骤为整体返回步骤数(例如)。再具体一点,<br><code>startUpdates(from start: Date,
withHandler handler: @escaping CMPedometerHandler)</code><br>不会为每个步骤计数(步骤计数1,步骤计数2等)调用。它合并数据并通过添加总步数仅被调用一次。<br><br>有没有一种方法可以为每个步行步骤调用该方法?</p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p>使用<a href="https://developer.apple.com/documentation/coremotion/cmpedometer/1778437-startpedometereventupdateswithha?language=objc" rel="noreferrer noopener nofollow"> <code>startPedometerEventUpdatesWithHandler:</code> </a><br><br> <strong>代码:</strong><br><pre><code>[self.pedometer startPedometerEventUpdatesWithHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
// this block is called for each live update
}];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何按步数获取CMPedometer数据?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/44744066/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/44744066/
</a>
</p>
页:
[1]