CMPedometer StepCounting不可用

我的代码是:

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!"]; } 

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

此设备上的计步function不可用!

我如何使它可用于步数计数?

你的代码是正确的,它会产生预期的结果。 iPhone 5没有硬件(苹果M7芯片)跟踪步骤,所以步数不可用。

你至less需要一台iPhone 5s

iPhone 4s,5和5c没有M7运动传感器协处理器,因此他们不会logging步骤。 iPhone 5s,6和6 Plus都有一个运动协处理器。