试图找到一种检测M7存在的方法.
如果M7不存在,查询CMStepCounter或CMMotionActivity类是否毫无意义?我的猜测是,在拥有iOS 7.0的非M7型号上,这些类可以获得数据,但效率并不高.使用更多的电池.
粗暴的方式是:
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"]) {
}
解决方法
使用Apple提供的API:
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
}
当然,此API仅适用于iOS 7或更高版本.因此,如果您需要支持iOS 5或6,那么您还需要在检查CMStepCounter类时包装此代码.