Is there any working algorithm to count steps on all iOS devices (with or without M7 chip)?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:20:17

问题


I want to make an app. that count user steps. So for that I have searched through the google but didn't found anything that could really help me. Although I came to know that by using Accelerometer data we can get the steps and I tried with this code

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    const float violence = 1.2;
        static BOOL beenhere;
        BOOL shake = FALSE;
        if (beenhere) return;
        beenhere = TRUE;
        if (acceleration.x > violence || acceleration.x < (-1* violence))
            shake = TRUE;
        if (acceleration.y > violence || acceleration.y < (-1* violence))
            shake = TRUE;
        if (acceleration.z > violence || acceleration.z < (-1* violence))
            shake = TRUE;
        if (shake) {  //(shake || length>=1.7)
            numSteps=numSteps+1;
            self.stepCountLabel.text = [NSString stringWithFormat:@"%d", numSteps];
        }
        beenhere = false;
}

But i am not getting the expected results. So if anyone out there know a better algorithm or a link that could help me out. Plzz share


回答1:


Please check out CMStepCounter for iOS 7. It has been deprecated in iOS 8, for iOS 8+, check out CMPedometer.



来源:https://stackoverflow.com/questions/29821806/is-there-any-working-algorithm-to-count-steps-on-all-ios-devices-with-or-withou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!