Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if M7 is present, a.k.a it is an iPhone 5S or newer?

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"]) {

}
like image 838
Gamma-Point Avatar asked Sep 24 '13 01:09

Gamma-Point


1 Answers

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.

like image 107
rmaddy Avatar answered Oct 09 '22 05:10

rmaddy