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

}
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top