CMPedometer StepCounting不可用

Man*_*gan 5 iphone objective-c ios core-motion

我的代码是:

if ([CMPedometer isStepCountingAvailable]) {

        self.pedometer = [[CMPedometer alloc] init];
    }
    else {
        NSLog(@"Step counting is not available on this device!");
        [SVProgressHUD showErrorWithStatus:@"Step counting is not available on this device!"];
    }
Run Code Online (Sandbox Code Playgroud)

当我在iOS8及更高版本的设备上运行它时,它说:

此设备无法进行步数计数!

我怎样才能将其用于计步?

Mat*_*uch 7

您的代码是正确的,它会产生预期的结果.iPhone 5没有硬件(Apple M7芯片)来跟踪步数,因此步进计数不可用.

你至少需要一部iPhone 5s