7

Trying to find a way to detect M7 being present.

Is it pointless to query CMStepCounter or CMMotionActivity class if M7 is not present? My guess is that on non M7 models having iOS 7.0, these classes get data but not that efficiently & use a lot more battery.

A crude way would be:

struct utsname systemInfo;

uname(&systemInfo);

model =  [[NSString alloc] initWithCString:systemInfo.machine
                                      encoding:NSUTF8StringEncoding];

version =  [[NSString alloc] initWithString:[[UIDevice currentDevice] systemVersion]];


if ([model compare:@"iPhone6,1"]) {

}
MÖRK
  • 954
  • 11
  • 31
Gamma-Point
  • 1,514
  • 13
  • 14
  • On non M7 models (anything but the 5S) those classes do not seem to get data. They require the M7 chip. Checking either isStepCountingAvailable or isActivityAvailable as below seems to work. – Jackson Sep 26 '13 at 16:20

1 Answers1

17

Use the APIs that Apple provides:

if ([CMStepCounter isStepCountingAvailable]) {
    // The device supports step counting
} else {
    // The device does not support step counting
}

if ([CMMotionActivityManager isActivityAvailable]) {
    // You can use CMMotionActivity
} else {
    // Nope, not supported
}

Of course this API is only on iOS 7 or later. So if you need to support iOS 5 or 6 then you need to wrap this code in a check for the CMStepCounter class too.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 2
    Actually, you don't need to explicitly check for the classes. If you're on iOS 6 or before, [CMStepCounter isStepCountingAvailable] will return false by virtue of the fact that CMStepCounter will be nil. (the same goes for [CMMotionActivityManager isActivityAvailable]) – clarkcox3 Jul 16 '14 at 23:22
  • 1
    CMStepCounter was deprecated in iOS 8. CMPedometer is used instead. [CMPedometer isStepCountingAvailable] works the same as its predecessor. Class reference: https://developer.apple.com/library/prerelease/ios/documentation/CoreMotion/Reference/CMPedometer_class/index.html – MÖRK Jul 29 '15 at 09:46